<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="common/css/sf.css" rel="stylesheet" type="text/css" />
<title>Logic: Logic in Coq</title>
<link href="common/jquery-ui/jquery-ui.css" rel="stylesheet">
<script src="common/jquery-ui/external/jquery/jquery.js"></script>
<script src="common/jquery-ui/jquery-ui.js"></script>
<script src="common/toggleproofs.js"></script>
<link href="common/css/lf.css" rel="stylesheet" type="text/css"/>
</head>

<body>

<div id="page">

<div id="header">
<div id='logoinheader'><a href='https://softwarefoundations.cis.upenn.edu'>
<img src='common/media/image/sf_logo_sm.png' alt='Software Foundations Logo'></a></div>
<div class='booktitleinheader'><a href='index.html'>Volume 1: Logical Foundations</a></div>
<ul id='menu'>
   <li class='section_name'><a href='toc.html'>Table of Contents</a></li>
   <li class='section_name'><a href='coqindex.html'>Index</a></li>
   <li class='section_name'><a href='deps.html'>Roadmap</a></li>
</ul>
</div>

<div id="main">

<h1 class="libtitle">Logic<span class="subtitle">Logic in Coq</span></h1>


<div class="code">

<span class="id" title="keyword">Set</span> <span class="id" title="var">Warnings</span> "-notation-overridden,-parsing,-deprecated-hint-without-locality".<br/>
<span class="id" title="keyword">From</span> <span class="id" title="var">LF</span> <span class="id" title="keyword">Require</span> <span class="id" title="keyword">Export</span> <a class="idref" href="Tactics.html#"><span class="id" title="library">Tactics</span></a>.<br/>
</div>

<div class="doc">
We have seen many examples of factual claims (<i>propositions</i>)
    and ways of presenting evidence of their truth (<i>proofs</i>).  In
    particular, we have worked extensively with <i>equality
    propositions</i> (<span class="inlinecode"><span class="id" title="var">e<sub>1</sub></span></span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" title="var">e<sub>2</sub></span></span>), implications (<span class="inlinecode"><span class="id" title="var">P</span></span> <span class="inlinecode">→</span> <span class="inlinecode"><span class="id" title="var">Q</span></span>), and quantified
    propositions (<span class="inlinecode"><span class="id" title="keyword">∀</span></span> <span class="inlinecode"><span class="id" title="var">x</span>,</span> <span class="inlinecode"><span class="id" title="var">P</span></span>).  In this chapter, we will see how
    Coq can be used to carry out other familiar forms of logical
    reasoning.

<div class="paragraph"> </div>

    Before diving into details, let's talk a bit about the status of
    mathematical statements in Coq.  Recall that Coq is a <i>typed</i>
    language, which means that every sensible expression in its world
    has an associated type.  Logical claims are no exception: any
    statement we might try to prove in Coq has a type, namely <span class="inlinecode"><span class="id" title="keyword">Prop</span></span>,
    the type of <i>propositions</i>.  We can see this with the <span class="inlinecode"><span class="id" title="keyword">Check</span></span>
    command: 
</div>
<div class="code">

<span class="id" title="keyword">Check</span> (3 <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> 3) : <span class="id" title="keyword">Prop</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Check</span> (<span class="id" title="keyword">∀</span> <a id="n:1" class="idref" href="#n:1"><span class="id" title="binder">n</span></a> <a id="m:2" class="idref" href="#m:2"><span class="id" title="binder">m</span></a> : <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#nat"><span class="id" title="inductive">nat</span></a>, <a class="idref" href="Logic.html#n:1"><span class="id" title="variable">n</span></a> <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> <a class="idref" href="Logic.html#m:2"><span class="id" title="variable">m</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Logic.html#m:2"><span class="id" title="variable">m</span></a> <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> <a class="idref" href="Logic.html#n:1"><span class="id" title="variable">n</span></a>) : <span class="id" title="keyword">Prop</span>.<br/>
</div>

<div class="doc">
Note that <i>all</i> syntactically well-formed propositions have type
    <span class="inlinecode"><span class="id" title="keyword">Prop</span></span> in Coq, regardless of whether they are true.

<div class="paragraph"> </div>

    Simply <i>being</i> a proposition is one thing; being <i>provable</i> is
    a different thing! 
</div>
<div class="code">

<span class="id" title="keyword">Check</span> 2 <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> 2 : <span class="id" title="keyword">Prop</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Check</span> 3 <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> 2 : <span class="id" title="keyword">Prop</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Check</span> <span class="id" title="keyword">∀</span> <a id="n:3" class="idref" href="#n:3"><span class="id" title="binder">n</span></a> : <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#nat"><span class="id" title="inductive">nat</span></a>, <a class="idref" href="Logic.html#n:3"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> 2 : <span class="id" title="keyword">Prop</span>.<br/>
</div>

<div class="doc">
Indeed, propositions not only have types: they are
    <i>first-class</i> entities that can be manipulated in all the same
    ways as any of the other things in Coq's world. 
<div class="paragraph"> </div>

 So far, we've seen one primary place that propositions can appear:
    in <span class="inlinecode"><span class="id" title="keyword">Theorem</span></span> (and <span class="inlinecode"><span class="id" title="keyword">Lemma</span></span> and <span class="inlinecode"><span class="id" title="keyword">Example</span></span>) declarations. 
</div>
<div class="code">

<span class="id" title="keyword">Theorem</span> <a id="plus_2_2_is_4" class="idref" href="#plus_2_2_is_4"><span class="id" title="lemma">plus_2_2_is_4</span></a> :<br/>
&nbsp;&nbsp;2 <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> 2 <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> 4.<br/>
<span class="id" title="keyword">Proof</span>. <span class="id" title="tactic">reflexivity</span>. <span class="id" title="keyword">Qed</span>.<br/>
</div>

<div class="doc">
But propositions can be used in many other ways.  For example, we
    can give a name to a proposition using a <span class="inlinecode"><span class="id" title="keyword">Definition</span></span>, just as we
    have given names to other kinds of expressions. 
</div>
<div class="code">

<span class="id" title="keyword">Definition</span> <a id="plus_claim" class="idref" href="#plus_claim"><span class="id" title="definition">plus_claim</span></a> : <span class="id" title="keyword">Prop</span> := 2 <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> 2 <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> 4.<br/>
<span class="id" title="keyword">Check</span> <a class="idref" href="Logic.html#plus_claim"><span class="id" title="definition">plus_claim</span></a> : <span class="id" title="keyword">Prop</span>.<br/>
</div>

<div class="doc">
We can later use this name in any situation where a proposition is
    expected -- for example, as the claim in a <span class="inlinecode"><span class="id" title="keyword">Theorem</span></span> declaration. 
</div>
<div class="code">

<span class="id" title="keyword">Theorem</span> <a id="plus_claim_is_true" class="idref" href="#plus_claim_is_true"><span class="id" title="lemma">plus_claim_is_true</span></a> :<br/>
&nbsp;&nbsp;<a class="idref" href="Logic.html#plus_claim"><span class="id" title="definition">plus_claim</span></a>.<br/>
<span class="id" title="keyword">Proof</span>. <span class="id" title="tactic">reflexivity</span>. <span class="id" title="keyword">Qed</span>.<br/>
</div>

<div class="doc">
We can also write <i>parameterized</i> propositions -- that is,
    functions that take arguments of some type and return a
    proposition. 
<div class="paragraph"> </div>

 For instance, the following function takes a number
    and returns a proposition asserting that this number is equal to
    three: 
</div>
<div class="code">

<span class="id" title="keyword">Definition</span> <a id="is_three" class="idref" href="#is_three"><span class="id" title="definition">is_three</span></a> (<a id="n:4" class="idref" href="#n:4"><span class="id" title="binder">n</span></a> : <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#nat"><span class="id" title="inductive">nat</span></a>) : <span class="id" title="keyword">Prop</span> :=<br/>
&nbsp;&nbsp;<a class="idref" href="Logic.html#n:4"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> 3.<br/>
<span class="id" title="keyword">Check</span> <a class="idref" href="Logic.html#is_three"><span class="id" title="definition">is_three</span></a> : <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#nat"><span class="id" title="inductive">nat</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <span class="id" title="keyword">Prop</span>.<br/>
</div>

<div class="doc">
In Coq, functions that return propositions are said to define
    <i>properties</i> of their arguments.

<div class="paragraph"> </div>

    For instance, here's a (polymorphic) property defining the
    familiar notion of an <i>injective function</i>. 
</div>
<div class="code">

<span class="id" title="keyword">Definition</span> <a id="injective" class="idref" href="#injective"><span class="id" title="definition">injective</span></a> {<a id="A:5" class="idref" href="#A:5"><span class="id" title="binder">A</span></a> <a id="B:6" class="idref" href="#B:6"><span class="id" title="binder">B</span></a>} (<a id="f:7" class="idref" href="#f:7"><span class="id" title="binder">f</span></a> : <a class="idref" href="Logic.html#A:5"><span class="id" title="variable">A</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="Logic.html#B:6"><span class="id" title="variable">B</span></a>) :=<br/>
&nbsp;&nbsp;<span class="id" title="keyword">∀</span> <a id="x:8" class="idref" href="#x:8"><span class="id" title="binder">x</span></a> <a id="y:9" class="idref" href="#y:9"><span class="id" title="binder">y</span></a> : <a class="idref" href="Logic.html#A:5"><span class="id" title="variable">A</span></a>, <a class="idref" href="Logic.html#f:7"><span class="id" title="variable">f</span></a> <a class="idref" href="Logic.html#x:8"><span class="id" title="variable">x</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Logic.html#f:7"><span class="id" title="variable">f</span></a> <a class="idref" href="Logic.html#y:9"><span class="id" title="variable">y</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="Logic.html#x:8"><span class="id" title="variable">x</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Logic.html#y:9"><span class="id" title="variable">y</span></a>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Lemma</span> <a id="succ_inj" class="idref" href="#succ_inj"><span class="id" title="lemma">succ_inj</span></a> : <a class="idref" href="Logic.html#injective"><span class="id" title="definition">injective</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#S"><span class="id" title="constructor">S</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">intros</span> <span class="id" title="var">n</span> <span class="id" title="var">m</span> <span class="id" title="var">H</span>. <span class="id" title="tactic">injection</span> <span class="id" title="var">H</span> <span class="id" title="keyword">as</span> <span class="id" title="var">H<sub>1</sub></span>. <span class="id" title="tactic">apply</span> <span class="id" title="var">H<sub>1</sub></span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>

<div class="doc">
The equality operator <span class="inlinecode">=</span> is also a function that returns a
    <span class="inlinecode"><span class="id" title="keyword">Prop</span></span>.

<div class="paragraph"> </div>

    The expression <span class="inlinecode"><span class="id" title="var">n</span></span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" title="var">m</span></span> is syntactic sugar for <span class="inlinecode"><span class="id" title="var">eq</span></span> <span class="inlinecode"><span class="id" title="var">n</span></span> <span class="inlinecode"><span class="id" title="var">m</span></span> (defined in
    Coq's standard library using the <span class="inlinecode"><span class="id" title="keyword">Notation</span></span> mechanism). Because
    <span class="inlinecode"><span class="id" title="var">eq</span></span> can be used with elements of any type, it is also
    polymorphic: 
</div>
<div class="code">

<span class="id" title="keyword">Check</span> @<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#eq"><span class="id" title="inductive">eq</span></a> : <span class="id" title="keyword">∀</span> <a id="A:10" class="idref" href="#A:10"><span class="id" title="binder">A</span></a> : <span class="id" title="keyword">Type</span>, <a class="idref" href="Logic.html#A:10"><span class="id" title="variable">A</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="Logic.html#A:10"><span class="id" title="variable">A</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <span class="id" title="keyword">Prop</span>.<br/>
</div>

<div class="doc">
(Notice that we wrote <span class="inlinecode">@<span class="id" title="var">eq</span></span> instead of <span class="inlinecode"><span class="id" title="var">eq</span></span>: The type
    argument <span class="inlinecode"><span class="id" title="var">A</span></span> to <span class="inlinecode"><span class="id" title="var">eq</span></span> is declared as implicit, and we need to turn
    off the inference of this implicit argument to see the full type
    of <span class="inlinecode"><span class="id" title="var">eq</span></span>.) 
</div>

<div class="doc">
<a id="lab167"></a><h1 class="section">Logical Connectives</h1>

<div class="paragraph"> </div>

<a id="lab168"></a><h2 class="section">Conjunction</h2>

<div class="paragraph"> </div>

 The <i>conjunction</i>, or <i>logical and</i>, of propositions <span class="inlinecode"><span class="id" title="var">A</span></span> and <span class="inlinecode"><span class="id" title="var">B</span></span>
    is written <span class="inlinecode"><span class="id" title="var">A</span></span> <span class="inlinecode">∧</span> <span class="inlinecode"><span class="id" title="var">B</span></span>, representing the claim that both <span class="inlinecode"><span class="id" title="var">A</span></span> and <span class="inlinecode"><span class="id" title="var">B</span></span>
    are true. 
</div>
<div class="code">

<span class="id" title="keyword">Example</span> <a id="and_example" class="idref" href="#and_example"><span class="id" title="definition">and_example</span></a> : 3 <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> 4 <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> 7 <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#ba2b0e492d2b4675a0acf3ea92aabadd"><span class="id" title="notation">∧</span></a> 2 <a class="idref" href="Basics.html#ea2ff3d561159081cea6fb2e8113cc<sub>54</sub>"><span class="id" title="notation">×</span></a> 2 <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> 4.<br/>
</div>

<div class="doc">
To prove a conjunction, use the <span class="inlinecode"><span class="id" title="tactic">split</span></span> tactic.  It will generate
    two subgoals, one for each part of the statement: 
</div>
<div class="code">

<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">split</span>.<br/>
&nbsp;&nbsp;- <span class="comment">(*&nbsp;3&nbsp;+&nbsp;4&nbsp;=&nbsp;7&nbsp;*)</span> <span class="id" title="tactic">reflexivity</span>.<br/>
&nbsp;&nbsp;- <span class="comment">(*&nbsp;2&nbsp;*&nbsp;2&nbsp;=&nbsp;4&nbsp;*)</span> <span class="id" title="tactic">reflexivity</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>

<div class="doc">
For any propositions <span class="inlinecode"><span class="id" title="var">A</span></span> and <span class="inlinecode"><span class="id" title="var">B</span></span>, if we assume that <span class="inlinecode"><span class="id" title="var">A</span></span> is true
    and that <span class="inlinecode"><span class="id" title="var">B</span></span> is true, we can conclude that <span class="inlinecode"><span class="id" title="var">A</span></span> <span class="inlinecode">∧</span> <span class="inlinecode"><span class="id" title="var">B</span></span> is also
    true. 
</div>
<div class="code">

<span class="id" title="keyword">Lemma</span> <a id="and_intro" class="idref" href="#and_intro"><span class="id" title="lemma">and_intro</span></a> : <span class="id" title="keyword">∀</span> <a id="A:11" class="idref" href="#A:11"><span class="id" title="binder">A</span></a> <a id="B:12" class="idref" href="#B:12"><span class="id" title="binder">B</span></a> : <span class="id" title="keyword">Prop</span>, <a class="idref" href="Logic.html#A:11"><span class="id" title="variable">A</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="Logic.html#B:12"><span class="id" title="variable">B</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="Logic.html#A:11"><span class="id" title="variable">A</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#ba2b0e492d2b4675a0acf3ea92aabadd"><span class="id" title="notation">∧</span></a> <a class="idref" href="Logic.html#B:12"><span class="id" title="variable">B</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">intros</span> <span class="id" title="var">A</span> <span class="id" title="var">B</span> <span class="id" title="var">HA</span> <span class="id" title="var">HB</span>. <span class="id" title="tactic">split</span>.<br/>
&nbsp;&nbsp;- <span class="id" title="tactic">apply</span> <span class="id" title="var">HA</span>.<br/>
&nbsp;&nbsp;- <span class="id" title="tactic">apply</span> <span class="id" title="var">HB</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>

<div class="doc">
Since applying a theorem with hypotheses to some goal has the
    effect of generating as many subgoals as there are hypotheses for
    that theorem, we can apply <span class="inlinecode"><span class="id" title="var">and_intro</span></span> to achieve the same effect
    as <span class="inlinecode"><span class="id" title="tactic">split</span></span>. 
</div>
<div class="code">

<span class="id" title="keyword">Example</span> <a id="and_example'" class="idref" href="#and_example'"><span class="id" title="definition">and_example'</span></a> : 3 <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> 4 <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> 7 <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#ba2b0e492d2b4675a0acf3ea92aabadd"><span class="id" title="notation">∧</span></a> 2 <a class="idref" href="Basics.html#ea2ff3d561159081cea6fb2e8113cc<sub>54</sub>"><span class="id" title="notation">×</span></a> 2 <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> 4.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">apply</span> <a class="idref" href="Logic.html#and_intro"><span class="id" title="lemma">and_intro</span></a>.<br/>
&nbsp;&nbsp;- <span class="comment">(*&nbsp;3&nbsp;+&nbsp;4&nbsp;=&nbsp;7&nbsp;*)</span> <span class="id" title="tactic">reflexivity</span>.<br/>
&nbsp;&nbsp;- <span class="comment">(*&nbsp;2&nbsp;+&nbsp;2&nbsp;=&nbsp;4&nbsp;*)</span> <span class="id" title="tactic">reflexivity</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>

<div class="doc">
<a id="lab169"></a><h4 class="section">Exercise: 2 stars, standard (and_exercise)</h4>

</div>
<div class="code">
<span class="id" title="keyword">Example</span> <a id="and_exercise" class="idref" href="#and_exercise"><span class="id" title="definition">and_exercise</span></a> :<br/>
&nbsp;&nbsp;<span class="id" title="keyword">∀</span> <a id="n:13" class="idref" href="#n:13"><span class="id" title="binder">n</span></a> <a id="m:14" class="idref" href="#m:14"><span class="id" title="binder">m</span></a> : <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#nat"><span class="id" title="inductive">nat</span></a>, <a class="idref" href="Logic.html#n:13"><span class="id" title="variable">n</span></a> <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> <a class="idref" href="Logic.html#m:14"><span class="id" title="variable">m</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> 0 <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="Logic.html#n:13"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> 0 <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#ba2b0e492d2b4675a0acf3ea92aabadd"><span class="id" title="notation">∧</span></a> <a class="idref" href="Logic.html#m:14"><span class="id" title="variable">m</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> 0.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="comment">(*&nbsp;FILL&nbsp;IN&nbsp;HERE&nbsp;*)</span> <span class="id" title="var">Admitted</span>.<br/>
<font size=-2>&#9744;</font>
</div>

<div class="doc"> 
<div class="paragraph"> </div>

 So much for proving conjunctive statements.  To go in the other
    direction -- i.e., to <i>use</i> a conjunctive hypothesis to help prove
    something else -- we employ the <span class="inlinecode"><span class="id" title="tactic">destruct</span></span> tactic.

<div class="paragraph"> </div>

    If the proof context contains a hypothesis <span class="inlinecode"><span class="id" title="var">H</span></span> of the form
    <span class="inlinecode"><span class="id" title="var">A</span></span> <span class="inlinecode">∧</span> <span class="inlinecode"><span class="id" title="var">B</span></span>, writing <span class="inlinecode"><span class="id" title="tactic">destruct</span></span> <span class="inlinecode"><span class="id" title="var">H</span></span> <span class="inlinecode"><span class="id" title="keyword">as</span></span> <span class="inlinecode">[<span class="id" title="var">HA</span></span> <span class="inlinecode"><span class="id" title="var">HB</span>]</span> will remove <span class="inlinecode"><span class="id" title="var">H</span></span> from the
    context and add two new hypotheses: <span class="inlinecode"><span class="id" title="var">HA</span></span>, stating that <span class="inlinecode"><span class="id" title="var">A</span></span> is
    true, and <span class="inlinecode"><span class="id" title="var">HB</span></span>, stating that <span class="inlinecode"><span class="id" title="var">B</span></span> is true.  
</div>
<div class="code">

<span class="id" title="keyword">Lemma</span> <a id="and_example2" class="idref" href="#and_example2"><span class="id" title="lemma">and_example2</span></a> :<br/>
&nbsp;&nbsp;<span class="id" title="keyword">∀</span> <a id="n:15" class="idref" href="#n:15"><span class="id" title="binder">n</span></a> <a id="m:16" class="idref" href="#m:16"><span class="id" title="binder">m</span></a> : <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#nat"><span class="id" title="inductive">nat</span></a>, <a class="idref" href="Logic.html#n:15"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> 0 <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#ba2b0e492d2b4675a0acf3ea92aabadd"><span class="id" title="notation">∧</span></a> <a class="idref" href="Logic.html#m:16"><span class="id" title="variable">m</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> 0 <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="Logic.html#n:15"><span class="id" title="variable">n</span></a> <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> <a class="idref" href="Logic.html#m:16"><span class="id" title="variable">m</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> 0.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="comment">(*&nbsp;WORKED&nbsp;IN&nbsp;CLASS&nbsp;*)</span><br/>
&nbsp;&nbsp;<span class="id" title="tactic">intros</span> <span class="id" title="var">n</span> <span class="id" title="var">m</span> <span class="id" title="var">H</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">destruct</span> <span class="id" title="var">H</span> <span class="id" title="keyword">as</span> [<span class="id" title="var">Hn</span> <span class="id" title="var">Hm</span>].<br/>
&nbsp;&nbsp;<span class="id" title="tactic">rewrite</span> <span class="id" title="var">Hn</span>. <span class="id" title="tactic">rewrite</span> <span class="id" title="var">Hm</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">reflexivity</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>

<div class="doc">
As usual, we can also destruct <span class="inlinecode"><span class="id" title="var">H</span></span> right when we introduce it,
    instead of introducing and then destructing it: 
</div>
<div class="code">

<span class="id" title="keyword">Lemma</span> <a id="and_example2'" class="idref" href="#and_example2'"><span class="id" title="lemma">and_example2'</span></a> :<br/>
&nbsp;&nbsp;<span class="id" title="keyword">∀</span> <a id="n:17" class="idref" href="#n:17"><span class="id" title="binder">n</span></a> <a id="m:18" class="idref" href="#m:18"><span class="id" title="binder">m</span></a> : <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#nat"><span class="id" title="inductive">nat</span></a>, <a class="idref" href="Logic.html#n:17"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> 0 <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#ba2b0e492d2b4675a0acf3ea92aabadd"><span class="id" title="notation">∧</span></a> <a class="idref" href="Logic.html#m:18"><span class="id" title="variable">m</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> 0 <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="Logic.html#n:17"><span class="id" title="variable">n</span></a> <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> <a class="idref" href="Logic.html#m:18"><span class="id" title="variable">m</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> 0.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">intros</span> <span class="id" title="var">n</span> <span class="id" title="var">m</span> [<span class="id" title="var">Hn</span> <span class="id" title="var">Hm</span>].<br/>
&nbsp;&nbsp;<span class="id" title="tactic">rewrite</span> <span class="id" title="var">Hn</span>. <span class="id" title="tactic">rewrite</span> <span class="id" title="var">Hm</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">reflexivity</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>

<div class="doc">
You may wonder why we bothered packing the two hypotheses <span class="inlinecode"><span class="id" title="var">n</span></span> <span class="inlinecode">=</span> <span class="inlinecode">0</span>
    and <span class="inlinecode"><span class="id" title="var">m</span></span> <span class="inlinecode">=</span> <span class="inlinecode">0</span> into a single conjunction, since we could have also
    stated the theorem with two separate premises: 
</div>
<div class="code">

<span class="id" title="keyword">Lemma</span> <a id="and_example2''" class="idref" href="#and_example2''"><span class="id" title="lemma">and_example2''</span></a> :<br/>
&nbsp;&nbsp;<span class="id" title="keyword">∀</span> <a id="n:19" class="idref" href="#n:19"><span class="id" title="binder">n</span></a> <a id="m:20" class="idref" href="#m:20"><span class="id" title="binder">m</span></a> : <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#nat"><span class="id" title="inductive">nat</span></a>, <a class="idref" href="Logic.html#n:19"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> 0 <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="Logic.html#m:20"><span class="id" title="variable">m</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> 0 <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="Logic.html#n:19"><span class="id" title="variable">n</span></a> <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> <a class="idref" href="Logic.html#m:20"><span class="id" title="variable">m</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> 0.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">intros</span> <span class="id" title="var">n</span> <span class="id" title="var">m</span> <span class="id" title="var">Hn</span> <span class="id" title="var">Hm</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">rewrite</span> <span class="id" title="var">Hn</span>. <span class="id" title="tactic">rewrite</span> <span class="id" title="var">Hm</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">reflexivity</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>

<div class="doc">
For this specific theorem, both formulations are fine.  But
    it's important to understand how to work with conjunctive
    hypotheses because conjunctions often arise from intermediate
    steps in proofs, especially in larger developments.  Here's a
    simple example: 
</div>
<div class="code">

<span class="id" title="keyword">Lemma</span> <a id="and_example3" class="idref" href="#and_example3"><span class="id" title="lemma">and_example3</span></a> :<br/>
&nbsp;&nbsp;<span class="id" title="keyword">∀</span> <a id="n:21" class="idref" href="#n:21"><span class="id" title="binder">n</span></a> <a id="m:22" class="idref" href="#m:22"><span class="id" title="binder">m</span></a> : <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#nat"><span class="id" title="inductive">nat</span></a>, <a class="idref" href="Logic.html#n:21"><span class="id" title="variable">n</span></a> <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> <a class="idref" href="Logic.html#m:22"><span class="id" title="variable">m</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> 0 <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="Logic.html#n:21"><span class="id" title="variable">n</span></a> <a class="idref" href="Basics.html#ea2ff3d561159081cea6fb2e8113cc<sub>54</sub>"><span class="id" title="notation">×</span></a> <a class="idref" href="Logic.html#m:22"><span class="id" title="variable">m</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> 0.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="comment">(*&nbsp;WORKED&nbsp;IN&nbsp;CLASS&nbsp;*)</span><br/>
&nbsp;&nbsp;<span class="id" title="tactic">intros</span> <span class="id" title="var">n</span> <span class="id" title="var">m</span> <span class="id" title="var">H</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">apply</span> <a class="idref" href="Logic.html#and_exercise"><span class="id" title="axiom">and_exercise</span></a> <span class="id" title="keyword">in</span> <span class="id" title="var">H</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">destruct</span> <span class="id" title="var">H</span> <span class="id" title="keyword">as</span> [<span class="id" title="var">Hn</span> <span class="id" title="var">Hm</span>].<br/>
&nbsp;&nbsp;<span class="id" title="tactic">rewrite</span> <span class="id" title="var">Hn</span>. <span class="id" title="tactic">reflexivity</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>

<div class="doc">
Another common situation with conjunctions is that we know
    <span class="inlinecode"><span class="id" title="var">A</span></span> <span class="inlinecode">∧</span> <span class="inlinecode"><span class="id" title="var">B</span></span> but in some context we need just <span class="inlinecode"><span class="id" title="var">A</span></span> or just <span class="inlinecode"><span class="id" title="var">B</span></span>.
    In such cases we can do a <span class="inlinecode"><span class="id" title="tactic">destruct</span></span> (possibly as part of
    an <span class="inlinecode"><span class="id" title="tactic">intros</span></span>) and use an underscore pattern <span class="inlinecode"><span class="id" title="var">_</span></span> to indicate
    that the unneeded conjunct should just be thrown away. 
</div>
<div class="code">

<span class="id" title="keyword">Lemma</span> <a id="proj1" class="idref" href="#proj1"><span class="id" title="lemma">proj1</span></a> : <span class="id" title="keyword">∀</span> <a id="P:23" class="idref" href="#P:23"><span class="id" title="binder">P</span></a> <a id="Q:24" class="idref" href="#Q:24"><span class="id" title="binder">Q</span></a> : <span class="id" title="keyword">Prop</span>,<br/>
&nbsp;&nbsp;<a class="idref" href="Logic.html#P:23"><span class="id" title="variable">P</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#ba2b0e492d2b4675a0acf3ea92aabadd"><span class="id" title="notation">∧</span></a> <a class="idref" href="Logic.html#Q:24"><span class="id" title="variable">Q</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="Logic.html#P:23"><span class="id" title="variable">P</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">intros</span> <span class="id" title="var">P</span> <span class="id" title="var">Q</span> <span class="id" title="var">HPQ</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">destruct</span> <span class="id" title="var">HPQ</span> <span class="id" title="keyword">as</span> [<span class="id" title="var">HP</span> <span class="id" title="var">_</span>].<br/>
&nbsp;&nbsp;<span class="id" title="tactic">apply</span> <span class="id" title="var">HP</span>. <span class="id" title="keyword">Qed</span>.<br/>
</div>

<div class="doc">
<a id="lab170"></a><h4 class="section">Exercise: 1 star, standard, optional (proj2)</h4>

</div>
<div class="code">
<span class="id" title="keyword">Lemma</span> <a id="proj2" class="idref" href="#proj2"><span class="id" title="lemma">proj2</span></a> : <span class="id" title="keyword">∀</span> <a id="P:25" class="idref" href="#P:25"><span class="id" title="binder">P</span></a> <a id="Q:26" class="idref" href="#Q:26"><span class="id" title="binder">Q</span></a> : <span class="id" title="keyword">Prop</span>,<br/>
&nbsp;&nbsp;<a class="idref" href="Logic.html#P:25"><span class="id" title="variable">P</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#ba2b0e492d2b4675a0acf3ea92aabadd"><span class="id" title="notation">∧</span></a> <a class="idref" href="Logic.html#Q:26"><span class="id" title="variable">Q</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="Logic.html#Q:26"><span class="id" title="variable">Q</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="comment">(*&nbsp;FILL&nbsp;IN&nbsp;HERE&nbsp;*)</span> <span class="id" title="var">Admitted</span>.<br/>
<font size=-2>&#9744;</font>
</div>

<div class="doc"> 
<div class="paragraph"> </div>

 Finally, we sometimes need to rearrange the order of conjunctions
    and/or the grouping of multi-way conjunctions.  The following
    commutativity and associativity theorems are handy in such
    cases. 
</div>
<div class="code">

<span class="id" title="keyword">Theorem</span> <a id="and_commut" class="idref" href="#and_commut"><span class="id" title="lemma">and_commut</span></a> : <span class="id" title="keyword">∀</span> <a id="P:27" class="idref" href="#P:27"><span class="id" title="binder">P</span></a> <a id="Q:28" class="idref" href="#Q:28"><span class="id" title="binder">Q</span></a> : <span class="id" title="keyword">Prop</span>,<br/>
&nbsp;&nbsp;<a class="idref" href="Logic.html#P:27"><span class="id" title="variable">P</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#ba2b0e492d2b4675a0acf3ea92aabadd"><span class="id" title="notation">∧</span></a> <a class="idref" href="Logic.html#Q:28"><span class="id" title="variable">Q</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="Logic.html#Q:28"><span class="id" title="variable">Q</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#ba2b0e492d2b4675a0acf3ea92aabadd"><span class="id" title="notation">∧</span></a> <a class="idref" href="Logic.html#P:27"><span class="id" title="variable">P</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">intros</span> <span class="id" title="var">P</span> <span class="id" title="var">Q</span> [<span class="id" title="var">HP</span> <span class="id" title="var">HQ</span>].<br/>
&nbsp;&nbsp;<span class="id" title="tactic">split</span>.<br/>
&nbsp;&nbsp;&nbsp;&nbsp;- <span class="comment">(*&nbsp;left&nbsp;*)</span> <span class="id" title="tactic">apply</span> <span class="id" title="var">HQ</span>.<br/>
&nbsp;&nbsp;&nbsp;&nbsp;- <span class="comment">(*&nbsp;right&nbsp;*)</span> <span class="id" title="tactic">apply</span> <span class="id" title="var">HP</span>. <span class="id" title="keyword">Qed</span>.<br/>
</div>

<div class="doc">
<a id="lab171"></a><h4 class="section">Exercise: 2 stars, standard (and_assoc)</h4>
 (In the following proof of associativity, notice how the <i>nested</i>
    <span class="inlinecode"><span class="id" title="tactic">intros</span></span> pattern breaks the hypothesis <span class="inlinecode"><span class="id" title="var">H</span></span> <span class="inlinecode">:</span> <span class="inlinecode"><span class="id" title="var">P</span></span> <span class="inlinecode">∧</span> <span class="inlinecode">(<span class="id" title="var">Q</span></span> <span class="inlinecode">∧</span> <span class="inlinecode"><span class="id" title="var">R</span>)</span> down into
    <span class="inlinecode"><span class="id" title="var">HP</span></span> <span class="inlinecode">:</span> <span class="inlinecode"><span class="id" title="var">P</span></span>, <span class="inlinecode"><span class="id" title="var">HQ</span></span> <span class="inlinecode">:</span> <span class="inlinecode"><span class="id" title="var">Q</span></span>, and <span class="inlinecode"><span class="id" title="var">HR</span></span> <span class="inlinecode">:</span> <span class="inlinecode"><span class="id" title="var">R</span></span>.  Finish the proof from
    there.) 
</div>
<div class="code">

<span class="id" title="keyword">Theorem</span> <a id="and_assoc" class="idref" href="#and_assoc"><span class="id" title="lemma">and_assoc</span></a> : <span class="id" title="keyword">∀</span> <a id="P:29" class="idref" href="#P:29"><span class="id" title="binder">P</span></a> <a id="Q:30" class="idref" href="#Q:30"><span class="id" title="binder">Q</span></a> <a id="R:31" class="idref" href="#R:31"><span class="id" title="binder">R</span></a> : <span class="id" title="keyword">Prop</span>,<br/>
&nbsp;&nbsp;<a class="idref" href="Logic.html#P:29"><span class="id" title="variable">P</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#ba2b0e492d2b4675a0acf3ea92aabadd"><span class="id" title="notation">∧</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#ba2b0e492d2b4675a0acf3ea92aabadd"><span class="id" title="notation">(</span></a><a class="idref" href="Logic.html#Q:30"><span class="id" title="variable">Q</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#ba2b0e492d2b4675a0acf3ea92aabadd"><span class="id" title="notation">∧</span></a> <a class="idref" href="Logic.html#R:31"><span class="id" title="variable">R</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#ba2b0e492d2b4675a0acf3ea92aabadd"><span class="id" title="notation">)</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#ba2b0e492d2b4675a0acf3ea92aabadd"><span class="id" title="notation">(</span></a><a class="idref" href="Logic.html#P:29"><span class="id" title="variable">P</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#ba2b0e492d2b4675a0acf3ea92aabadd"><span class="id" title="notation">∧</span></a> <a class="idref" href="Logic.html#Q:30"><span class="id" title="variable">Q</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#ba2b0e492d2b4675a0acf3ea92aabadd"><span class="id" title="notation">)</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#ba2b0e492d2b4675a0acf3ea92aabadd"><span class="id" title="notation">∧</span></a> <a class="idref" href="Logic.html#R:31"><span class="id" title="variable">R</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">intros</span> <span class="id" title="var">P</span> <span class="id" title="var">Q</span> <span class="id" title="var">R</span> [<span class="id" title="var">HP</span> [<span class="id" title="var">HQ</span> <span class="id" title="var">HR</span>]].<br/>
&nbsp;&nbsp;<span class="comment">(*&nbsp;FILL&nbsp;IN&nbsp;HERE&nbsp;*)</span> <span class="id" title="var">Admitted</span>.<br/>
<font size=-2>&#9744;</font>
</div>

<div class="doc"> 
<div class="paragraph"> </div>

 By the way, the infix notation <span class="inlinecode">∧</span> is actually just syntactic
    sugar for <span class="inlinecode"><span class="id" title="var">and</span></span> <span class="inlinecode"><span class="id" title="var">A</span></span> <span class="inlinecode"><span class="id" title="var">B</span></span>.  That is, <span class="inlinecode"><span class="id" title="var">and</span></span> is a Coq operator that takes
    two propositions as arguments and yields a proposition. 
</div>
<div class="code">

<span class="id" title="keyword">Check</span> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#and"><span class="id" title="inductive">and</span></a> : <span class="id" title="keyword">Prop</span> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <span class="id" title="keyword">Prop</span> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <span class="id" title="keyword">Prop</span>.<br/>
</div>

<div class="doc">
<a id="lab172"></a><h2 class="section">Disjunction</h2>

<div class="paragraph"> </div>

 Another important connective is the <i>disjunction</i>, or <i>logical or</i>,
    of two propositions: <span class="inlinecode"><span class="id" title="var">A</span></span> <span class="inlinecode">∨</span> <span class="inlinecode"><span class="id" title="var">B</span></span> is true when either <span class="inlinecode"><span class="id" title="var">A</span></span> or <span class="inlinecode"><span class="id" title="var">B</span></span>
    is.  (This infix notation stands for <span class="inlinecode"><span class="id" title="var">or</span></span> <span class="inlinecode"><span class="id" title="var">A</span></span> <span class="inlinecode"><span class="id" title="var">B</span></span>, where <span class="inlinecode"><span class="id" title="var">or</span></span> <span class="inlinecode">:</span> <span class="inlinecode"><span class="id" title="keyword">Prop</span></span> <span class="inlinecode">→</span>
    <span class="inlinecode"><span class="id" title="keyword">Prop</span></span> <span class="inlinecode">→</span> <span class="inlinecode"><span class="id" title="keyword">Prop</span></span>.) 
<div class="paragraph"> </div>

 To use a disjunctive hypothesis in a proof, we proceed by case
    analysis (which, as with other data types like <span class="inlinecode"><span class="id" title="var">nat</span></span>, can be done
    explicitly with <span class="inlinecode"><span class="id" title="tactic">destruct</span></span> or implicitly with an <span class="inlinecode"><span class="id" title="tactic">intros</span></span>
    pattern): 
</div>
<div class="code">

<span class="id" title="keyword">Lemma</span> <a id="factor_is_O" class="idref" href="#factor_is_O"><span class="id" title="lemma">factor_is_O</span></a>:<br/>
&nbsp;&nbsp;<span class="id" title="keyword">∀</span> <a id="n:32" class="idref" href="#n:32"><span class="id" title="binder">n</span></a> <a id="m:33" class="idref" href="#m:33"><span class="id" title="binder">m</span></a> : <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#nat"><span class="id" title="inductive">nat</span></a>, <a class="idref" href="Logic.html#n:32"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> 0 <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#f031fe1957c4a4a8e217aa46af2b4e<sub>25</sub>"><span class="id" title="notation">∨</span></a> <a class="idref" href="Logic.html#m:33"><span class="id" title="variable">m</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> 0 <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="Logic.html#n:32"><span class="id" title="variable">n</span></a> <a class="idref" href="Basics.html#ea2ff3d561159081cea6fb2e8113cc<sub>54</sub>"><span class="id" title="notation">×</span></a> <a class="idref" href="Logic.html#m:33"><span class="id" title="variable">m</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> 0.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="comment">(*&nbsp;This&nbsp;pattern&nbsp;implicitly&nbsp;does&nbsp;case&nbsp;analysis&nbsp;on<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="inlinecode"><span class="id" title="var">n</span></span> <span class="inlinecode">=</span> <span class="inlinecode">0</span> <span class="inlinecode">∨</span> <span class="inlinecode"><span class="id" title="var">m</span></span> <span class="inlinecode">=</span> <span class="inlinecode">0</span>&nbsp;*)</span><br/>
&nbsp;&nbsp;<span class="id" title="tactic">intros</span> <span class="id" title="var">n</span> <span class="id" title="var">m</span> [<span class="id" title="var">Hn</span> | <span class="id" title="var">Hm</span>].<br/>
&nbsp;&nbsp;- <span class="comment">(*&nbsp;Here,&nbsp;<span class="inlinecode"><span class="id" title="var">n</span></span> <span class="inlinecode">=</span> <span class="inlinecode">0</span>&nbsp;*)</span><br/>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="id" title="tactic">rewrite</span> <span class="id" title="var">Hn</span>. <span class="id" title="tactic">reflexivity</span>.<br/>
&nbsp;&nbsp;- <span class="comment">(*&nbsp;Here,&nbsp;<span class="inlinecode"><span class="id" title="var">m</span></span> <span class="inlinecode">=</span> <span class="inlinecode">0</span>&nbsp;*)</span><br/>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="id" title="tactic">rewrite</span> <span class="id" title="var">Hm</span>. <span class="id" title="tactic">rewrite</span> &lt;- <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Peano.html#mult_n_O"><span class="id" title="lemma">mult_n_O</span></a>.<br/>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="id" title="tactic">reflexivity</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>

<div class="doc">
Conversely, to show that a disjunction holds, it suffices to show
    that one of its sides holds. This is done via two tactics, <span class="inlinecode"><span class="id" title="tactic">left</span></span>
    and <span class="inlinecode"><span class="id" title="tactic">right</span></span>.  As their names imply, the first one requires proving
    the left side of the disjunction, while the second requires
    proving its right side.  Here is a trivial use... 
</div>
<div class="code">

<span class="id" title="keyword">Lemma</span> <a id="or_intro_l" class="idref" href="#or_intro_l"><span class="id" title="lemma">or_intro_l</span></a> : <span class="id" title="keyword">∀</span> <a id="A:34" class="idref" href="#A:34"><span class="id" title="binder">A</span></a> <a id="B:35" class="idref" href="#B:35"><span class="id" title="binder">B</span></a> : <span class="id" title="keyword">Prop</span>, <a class="idref" href="Logic.html#A:34"><span class="id" title="variable">A</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="Logic.html#A:34"><span class="id" title="variable">A</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#f031fe1957c4a4a8e217aa46af2b4e<sub>25</sub>"><span class="id" title="notation">∨</span></a> <a class="idref" href="Logic.html#B:35"><span class="id" title="variable">B</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">intros</span> <span class="id" title="var">A</span> <span class="id" title="var">B</span> <span class="id" title="var">HA</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">left</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">apply</span> <span class="id" title="var">HA</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>

<div class="doc">
... and here is a slightly more interesting example requiring both
    <span class="inlinecode"><span class="id" title="tactic">left</span></span> and <span class="inlinecode"><span class="id" title="tactic">right</span></span>: 
</div>
<div class="code">

<span class="id" title="keyword">Lemma</span> <a id="zero_or_succ" class="idref" href="#zero_or_succ"><span class="id" title="lemma">zero_or_succ</span></a> :<br/>
&nbsp;&nbsp;<span class="id" title="keyword">∀</span> <a id="n:36" class="idref" href="#n:36"><span class="id" title="binder">n</span></a> : <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#nat"><span class="id" title="inductive">nat</span></a>, <a class="idref" href="Logic.html#n:36"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> 0 <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#f031fe1957c4a4a8e217aa46af2b4e<sub>25</sub>"><span class="id" title="notation">∨</span></a> <a class="idref" href="Logic.html#n:36"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#S"><span class="id" title="constructor">S</span></a> (<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Peano.html#pred"><span class="id" title="abbreviation">pred</span></a> <a class="idref" href="Logic.html#n:36"><span class="id" title="variable">n</span></a>).<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="comment">(*&nbsp;WORKED&nbsp;IN&nbsp;CLASS&nbsp;*)</span><br/>
&nbsp;&nbsp;<span class="id" title="tactic">intros</span> [|<span class="id" title="var">n'</span>].<br/>
&nbsp;&nbsp;- <span class="id" title="tactic">left</span>. <span class="id" title="tactic">reflexivity</span>.<br/>
&nbsp;&nbsp;- <span class="id" title="tactic">right</span>. <span class="id" title="tactic">reflexivity</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/><hr class='doublespaceincode'/>
</div>

<div class="doc">
<a id="lab175"></a><h2 class="section">Falsehood and Negation</h2>
 So far, we have mostly been concerned with proving that certain
    things are <i>true</i> -- addition is commutative, appending lists is
    associative, etc.  Of course, we may also be interested in
    negative results, demonstrating that some given proposition is
    <i>not</i> true. Such statements are expressed with the logical
    negation operator <span class="inlinecode">¬</span>. 
<div class="paragraph"> </div>

 To see how negation works, recall the <i>principle of explosion</i>
    from the <a href="Tactics.html"><span class="inlineref">Tactics</span></a> chapter, which asserts that, if we assume a
    contradiction, then any other proposition can be derived. 
    Following this intuition, we could define <span class="inlinecode">¬</span> <span class="inlinecode"><span class="id" title="var">P</span></span> ("not <span class="inlinecode"><span class="id" title="var">P</span></span>") as
    <span class="inlinecode"><span class="id" title="keyword">∀</span></span> <span class="inlinecode"><span class="id" title="var">Q</span>,</span> <span class="inlinecode"><span class="id" title="var">P</span></span> <span class="inlinecode">→</span> <span class="inlinecode"><span class="id" title="var">Q</span></span>.

<div class="paragraph"> </div>

    Coq actually makes a slightly different (but equivalent) choice,
    defining <span class="inlinecode">¬</span> <span class="inlinecode"><span class="id" title="var">P</span></span> as <span class="inlinecode"><span class="id" title="var">P</span></span> <span class="inlinecode">→</span> <span class="inlinecode"><span class="id" title="var">False</span></span>, where <span class="inlinecode"><span class="id" title="var">False</span></span> is a specific
    contradictory proposition defined in the standard library. 
</div>
<div class="code">

<span class="id" title="keyword">Module</span> <a id="MyNot" class="idref" href="#MyNot"><span class="id" title="module">MyNot</span></a>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Definition</span> <a id="MyNot.not" class="idref" href="#MyNot.not"><span class="id" title="definition">not</span></a> (<a id="P:41" class="idref" href="#P:41"><span class="id" title="binder">P</span></a>:<span class="id" title="keyword">Prop</span>) := <a class="idref" href="Logic.html#P:41"><span class="id" title="variable">P</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#False"><span class="id" title="inductive">False</span></a>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Notation</span> <a id="5e8c5653f7c83aa667e9835b5fd107fe" class="idref" href="#5e8c5653f7c83aa667e9835b5fd107fe"><span class="id" title="notation">&quot;</span></a>~ x" := (<a class="idref" href="Logic.html#MyNot.not"><span class="id" title="definition">not</span></a> <span class="id" title="var">x</span>) : <span class="id" title="var">type_scope</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Check</span> <a class="idref" href="Logic.html#MyNot.not"><span class="id" title="definition">not</span></a> : <span class="id" title="keyword">Prop</span> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <span class="id" title="keyword">Prop</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">End</span> <a class="idref" href="Logic.html#MyNot"><span class="id" title="module">MyNot</span></a>.<br/>
</div>

<div class="doc">
Since <span class="inlinecode"><span class="id" title="var">False</span></span> is a contradictory proposition, the principle of
    explosion also applies to it. If we get <span class="inlinecode"><span class="id" title="var">False</span></span> into the proof
    context, we can use <span class="inlinecode"><span class="id" title="tactic">destruct</span></span> on it to complete any goal: 
</div>
<div class="code">

<span class="id" title="keyword">Theorem</span> <a id="ex_falso_quodlibet" class="idref" href="#ex_falso_quodlibet"><span class="id" title="lemma">ex_falso_quodlibet</span></a> : <span class="id" title="keyword">∀</span> (<a id="P:42" class="idref" href="#P:42"><span class="id" title="binder">P</span></a>:<span class="id" title="keyword">Prop</span>),<br/>
&nbsp;&nbsp;<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#False"><span class="id" title="inductive">False</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="Logic.html#P:42"><span class="id" title="variable">P</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="comment">(*&nbsp;WORKED&nbsp;IN&nbsp;CLASS&nbsp;*)</span><br/>
&nbsp;&nbsp;<span class="id" title="tactic">intros</span> <span class="id" title="var">P</span> <span class="id" title="var">contra</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">destruct</span> <span class="id" title="var">contra</span>. <span class="id" title="keyword">Qed</span>.<br/>
</div>

<div class="doc">
The Latin <i>ex falso quodlibet</i> means, literally, "from falsehood
    follows whatever you like"; this is another common name for the
    principle of explosion. 
<div class="paragraph"> </div>

<a id="lab176"></a><h4 class="section">Exercise: 2 stars, standard, optional (not_implies_our_not)</h4>
 Show that Coq's definition of negation implies the intuitive one
    mentioned above: 
</div>
<div class="code">

<span class="id" title="keyword">Fact</span> <a id="not_implies_our_not" class="idref" href="#not_implies_our_not"><span class="id" title="lemma">not_implies_our_not</span></a> : <span class="id" title="keyword">∀</span> (<a id="P:43" class="idref" href="#P:43"><span class="id" title="binder">P</span></a>:<span class="id" title="keyword">Prop</span>),<br/>
&nbsp;&nbsp;<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#63a68285c81db8f9bc456233bb9ed181"><span class="id" title="notation">¬</span></a> <a class="idref" href="Logic.html#P:43"><span class="id" title="variable">P</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">(</span></a><span class="id" title="keyword">∀</span> (<a id="Q:44" class="idref" href="#Q:44"><span class="id" title="binder">Q</span></a>:<span class="id" title="keyword">Prop</span>), <a class="idref" href="Logic.html#P:43"><span class="id" title="variable">P</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="Logic.html#Q:44"><span class="id" title="variable">Q</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">)</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="comment">(*&nbsp;FILL&nbsp;IN&nbsp;HERE&nbsp;*)</span> <span class="id" title="var">Admitted</span>.<br/>
<font size=-2>&#9744;</font>
</div>

<div class="doc"> 
<div class="paragraph"> </div>

 Inequality is a frequent enough example of negated statement
    that there is a special notation for it, <span class="inlinecode"><span class="id" title="var">x</span></span> <span class="inlinecode">≠</span> <span class="inlinecode"><span class="id" title="var">y</span></span>:
<br/>
<span class="inlinecode">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="id" title="keyword">Notation</span> "x &lt;&gt; y" := (~(<span class="id" title="var">x</span> = <span class="id" title="var">y</span>)).
</span>
<div class="paragraph"> </div>

 We can use <span class="inlinecode"><span class="id" title="var">not</span></span> to state that <span class="inlinecode">0</span> and <span class="inlinecode">1</span> are different elements
    of <span class="inlinecode"><span class="id" title="var">nat</span></span>: 
</div>
<div class="code">

<span class="id" title="keyword">Theorem</span> <a id="zero_not_one" class="idref" href="#zero_not_one"><span class="id" title="lemma">zero_not_one</span></a> : 0 <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'&lt;&gt;'_x"><span class="id" title="notation">≠</span></a> 1.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
</div>

<div class="doc">
The proposition <span class="inlinecode">0</span> <span class="inlinecode">≠</span> <span class="inlinecode">1</span> is exactly the same as
      <span class="inlinecode">~(0</span> <span class="inlinecode">=</span> <span class="inlinecode">1)</span>, that is <span class="inlinecode"><span class="id" title="var">not</span></span> <span class="inlinecode">(0</span> <span class="inlinecode">=</span> <span class="inlinecode">1)</span>, which unfolds to
      <span class="inlinecode">(0</span> <span class="inlinecode">=</span> <span class="inlinecode">1)</span> <span class="inlinecode">→</span> <span class="inlinecode"><span class="id" title="var">False</span></span>. (We use <span class="inlinecode"><span class="id" title="tactic">unfold</span></span> <span class="inlinecode"><span class="id" title="var">not</span></span> explicitly here
      to illustrate that point, but generally it can be omitted.) 
</div>
<div class="code">
&nbsp;&nbsp;<span class="id" title="tactic">unfold</span> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#not"><span class="id" title="definition">not</span></a>.<br/>
</div>

<div class="doc">
To prove an inequality, we may assume the opposite
      equality... 
</div>
<div class="code">
&nbsp;&nbsp;<span class="id" title="tactic">intros</span> <span class="id" title="var">contra</span>.<br/>
</div>

<div class="doc">
... and deduce a contradiction from it. Here, the
      equality <span class="inlinecode"><span class="id" title="var">O</span></span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" title="var">S</span></span> <span class="inlinecode"><span class="id" title="var">O</span></span> contradicts the disjointness of
      constructors <span class="inlinecode"><span class="id" title="var">O</span></span> and <span class="inlinecode"><span class="id" title="var">S</span></span>, so <span class="inlinecode"><span class="id" title="tactic">discriminate</span></span> takes care
      of it. 
</div>
<div class="code">
&nbsp;&nbsp;<span class="id" title="tactic">discriminate</span> <span class="id" title="var">contra</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>

<div class="doc">
It takes a little practice to get used to working with negation in
    Coq.  Even though you can see perfectly well why a statement
    involving negation is true, it can be a little tricky at first to
    make Coq understand it!  Here are proofs of a few familiar facts
    to get you warmed up. 
</div>
<div class="code">

<span class="id" title="keyword">Theorem</span> <a id="not_False" class="idref" href="#not_False"><span class="id" title="lemma">not_False</span></a> :<br/>
&nbsp;&nbsp;<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#63a68285c81db8f9bc456233bb9ed181"><span class="id" title="notation">¬</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#False"><span class="id" title="inductive">False</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">unfold</span> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#not"><span class="id" title="definition">not</span></a>. <span class="id" title="tactic">intros</span> <span class="id" title="var">H</span>. <span class="id" title="tactic">destruct</span> <span class="id" title="var">H</span>. <span class="id" title="keyword">Qed</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Theorem</span> <a id="contradiction_implies_anything" class="idref" href="#contradiction_implies_anything"><span class="id" title="lemma">contradiction_implies_anything</span></a> : <span class="id" title="keyword">∀</span> <a id="P:45" class="idref" href="#P:45"><span class="id" title="binder">P</span></a> <a id="Q:46" class="idref" href="#Q:46"><span class="id" title="binder">Q</span></a> : <span class="id" title="keyword">Prop</span>,<br/>
&nbsp;&nbsp;<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">(</span></a><a class="idref" href="Logic.html#P:45"><span class="id" title="variable">P</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#ba2b0e492d2b4675a0acf3ea92aabadd"><span class="id" title="notation">∧</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#63a68285c81db8f9bc456233bb9ed181"><span class="id" title="notation">¬</span></a><a class="idref" href="Logic.html#P:45"><span class="id" title="variable">P</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">)</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="Logic.html#Q:46"><span class="id" title="variable">Q</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="comment">(*&nbsp;WORKED&nbsp;IN&nbsp;CLASS&nbsp;*)</span><br/>
&nbsp;&nbsp;<span class="id" title="tactic">intros</span> <span class="id" title="var">P</span> <span class="id" title="var">Q</span> [<span class="id" title="var">HP</span> <span class="id" title="var">HNA</span>]. <span class="id" title="tactic">unfold</span> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#not"><span class="id" title="definition">not</span></a> <span class="id" title="keyword">in</span> <span class="id" title="var">HNA</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">apply</span> <span class="id" title="var">HNA</span> <span class="id" title="keyword">in</span> <span class="id" title="var">HP</span>. <span class="id" title="tactic">destruct</span> <span class="id" title="var">HP</span>. <span class="id" title="keyword">Qed</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Theorem</span> <a id="double_neg" class="idref" href="#double_neg"><span class="id" title="lemma">double_neg</span></a> : <span class="id" title="keyword">∀</span> <a id="P:47" class="idref" href="#P:47"><span class="id" title="binder">P</span></a> : <span class="id" title="keyword">Prop</span>,<br/>
&nbsp;&nbsp;<a class="idref" href="Logic.html#P:47"><span class="id" title="variable">P</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#63a68285c81db8f9bc456233bb9ed181"><span class="id" title="notation">~~</span></a><a class="idref" href="Logic.html#P:47"><span class="id" title="variable">P</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="comment">(*&nbsp;WORKED&nbsp;IN&nbsp;CLASS&nbsp;*)</span><br/>
&nbsp;&nbsp;<span class="id" title="tactic">intros</span> <span class="id" title="var">P</span> <span class="id" title="var">H</span>. <span class="id" title="tactic">unfold</span> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#not"><span class="id" title="definition">not</span></a>. <span class="id" title="tactic">intros</span> <span class="id" title="var">G</span>. <span class="id" title="tactic">apply</span> <span class="id" title="var">G</span>. <span class="id" title="tactic">apply</span> <span class="id" title="var">H</span>. <span class="id" title="keyword">Qed</span>.<br/>
</div>

<div class="doc">
<a id="lab177"></a><h4 class="section">Exercise: 2 stars, advanced (double_neg_inf)</h4>
 Write an informal proof of <span class="inlinecode"><span class="id" title="var">double_neg</span></span>:

<div class="paragraph"> </div>

   <i>Theorem</i>: <span class="inlinecode"><span class="id" title="var">P</span></span> implies <span class="inlinecode">~~<span class="id" title="var">P</span></span>, for any proposition <span class="inlinecode"><span class="id" title="var">P</span></span>. 
</div>
<div class="code">

<span class="comment">(*&nbsp;FILL&nbsp;IN&nbsp;HERE&nbsp;*)</span><br/><hr class='doublespaceincode'/>
<span class="comment">(*&nbsp;Do&nbsp;not&nbsp;modify&nbsp;the&nbsp;following&nbsp;line:&nbsp;*)</span><br/>
<span class="id" title="keyword">Definition</span> <a id="manual_grade_for_double_neg_inf" class="idref" href="#manual_grade_for_double_neg_inf"><span class="id" title="definition">manual_grade_for_double_neg_inf</span></a> : <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#option"><span class="id" title="inductive">option</span></a> (<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#nat"><span class="id" title="inductive">nat</span></a><a class="idref" href="Poly.html#11c698c8685bb8ab1cf725545c085ac<sub>4</sub>"><span class="id" title="notation">×</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Strings.String.html#string"><span class="id" title="inductive">string</span></a>) := <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#None"><span class="id" title="constructor">None</span></a>.<br/>
<font size=-2>&#9744;</font>
</div>

<div class="doc"> 
<div class="paragraph"> </div>

<a id="lab178"></a><h4 class="section">Exercise: 2 stars, standard, especially useful (contrapositive)</h4>

</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <a id="contrapositive" class="idref" href="#contrapositive"><span class="id" title="lemma">contrapositive</span></a> : <span class="id" title="keyword">∀</span> (<a id="P:48" class="idref" href="#P:48"><span class="id" title="binder">P</span></a> <a id="Q:49" class="idref" href="#Q:49"><span class="id" title="binder">Q</span></a> : <span class="id" title="keyword">Prop</span>),<br/>
&nbsp;&nbsp;<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">(</span></a><a class="idref" href="Logic.html#P:48"><span class="id" title="variable">P</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="Logic.html#Q:49"><span class="id" title="variable">Q</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">)</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">(</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#63a68285c81db8f9bc456233bb9ed181"><span class="id" title="notation">¬</span></a><a class="idref" href="Logic.html#Q:49"><span class="id" title="variable">Q</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#63a68285c81db8f9bc456233bb9ed181"><span class="id" title="notation">¬</span></a><a class="idref" href="Logic.html#P:48"><span class="id" title="variable">P</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">)</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="comment">(*&nbsp;FILL&nbsp;IN&nbsp;HERE&nbsp;*)</span> <span class="id" title="var">Admitted</span>.<br/>
<font size=-2>&#9744;</font>
</div>

<div class="doc"> 
<div class="paragraph"> </div>

<a id="lab179"></a><h4 class="section">Exercise: 1 star, standard (not_both_true_and_false)</h4>

</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <a id="not_both_true_and_false" class="idref" href="#not_both_true_and_false"><span class="id" title="lemma">not_both_true_and_false</span></a> : <span class="id" title="keyword">∀</span> <a id="P:50" class="idref" href="#P:50"><span class="id" title="binder">P</span></a> : <span class="id" title="keyword">Prop</span>,<br/>
&nbsp;&nbsp;<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#63a68285c81db8f9bc456233bb9ed181"><span class="id" title="notation">¬</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#63a68285c81db8f9bc456233bb9ed181"><span class="id" title="notation">(</span></a><a class="idref" href="Logic.html#P:50"><span class="id" title="variable">P</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#ba2b0e492d2b4675a0acf3ea92aabadd"><span class="id" title="notation">∧</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#63a68285c81db8f9bc456233bb9ed181"><span class="id" title="notation">¬</span></a><a class="idref" href="Logic.html#P:50"><span class="id" title="variable">P</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#63a68285c81db8f9bc456233bb9ed181"><span class="id" title="notation">)</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="comment">(*&nbsp;FILL&nbsp;IN&nbsp;HERE&nbsp;*)</span> <span class="id" title="var">Admitted</span>.<br/>
<font size=-2>&#9744;</font>
</div>

<div class="doc"> 
<div class="paragraph"> </div>

<a id="lab180"></a><h4 class="section">Exercise: 1 star, advanced (informal_not_PNP)</h4>
 Write an informal proof (in English) of the proposition <span class="inlinecode"><span class="id" title="keyword">∀</span></span> <span class="inlinecode"><span class="id" title="var">P</span></span>
    <span class="inlinecode">:</span> <span class="inlinecode"><span class="id" title="keyword">Prop</span>,</span> <span class="inlinecode">~(<span class="id" title="var">P</span></span> <span class="inlinecode">∧</span> <span class="inlinecode">¬<span class="id" title="var">P</span>)</span>. 
</div>
<div class="code">

<span class="comment">(*&nbsp;FILL&nbsp;IN&nbsp;HERE&nbsp;*)</span><br/><hr class='doublespaceincode'/>
<span class="comment">(*&nbsp;Do&nbsp;not&nbsp;modify&nbsp;the&nbsp;following&nbsp;line:&nbsp;*)</span><br/>
<span class="id" title="keyword">Definition</span> <a id="manual_grade_for_informal_not_PNP" class="idref" href="#manual_grade_for_informal_not_PNP"><span class="id" title="definition">manual_grade_for_informal_not_PNP</span></a> : <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#option"><span class="id" title="inductive">option</span></a> (<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#nat"><span class="id" title="inductive">nat</span></a><a class="idref" href="Poly.html#11c698c8685bb8ab1cf725545c085ac<sub>4</sub>"><span class="id" title="notation">×</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Strings.String.html#string"><span class="id" title="inductive">string</span></a>) := <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#None"><span class="id" title="constructor">None</span></a>.<br/>
<font size=-2>&#9744;</font>
</div>

<div class="doc"> 
<div class="paragraph"> </div>

 Since inequality involves a negation, it also requires a little
    practice to be able to work with it fluently.  Here is one useful
    trick.  If you are trying to prove a goal that is
    nonsensical (e.g., the goal state is <span class="inlinecode"><span class="id" title="var">false</span></span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" title="var">true</span></span>), apply
    <span class="inlinecode"><span class="id" title="var">ex_falso_quodlibet</span></span> to change the goal to <span class="inlinecode"><span class="id" title="var">False</span></span>.  This makes it
    easier to use assumptions of the form <span class="inlinecode">¬<span class="id" title="var">P</span></span> that may be available
    in the context -- in particular, assumptions of the form
    <span class="inlinecode"><span class="id" title="var">x</span>≠<span class="id" title="var">y</span></span>. 
</div>
<div class="code">

<span class="id" title="keyword">Theorem</span> <a id="not_true_is_false" class="idref" href="#not_true_is_false"><span class="id" title="lemma">not_true_is_false</span></a> : <span class="id" title="keyword">∀</span> <a id="b:51" class="idref" href="#b:51"><span class="id" title="binder">b</span></a> : <a class="idref" href="Basics.html#bool"><span class="id" title="inductive">bool</span></a>,<br/>
&nbsp;&nbsp;<a class="idref" href="Logic.html#b:51"><span class="id" title="variable">b</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'&lt;&gt;'_x"><span class="id" title="notation">≠</span></a> <a class="idref" href="Basics.html#true"><span class="id" title="constructor">true</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="Logic.html#b:51"><span class="id" title="variable">b</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Basics.html#false"><span class="id" title="constructor">false</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">intros</span> <span class="id" title="var">b</span> <span class="id" title="var">H</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">destruct</span> <span class="id" title="var">b</span> <span class="id" title="var">eqn</span>:<span class="id" title="var">HE</span>.<br/>
&nbsp;&nbsp;- <span class="comment">(*&nbsp;b&nbsp;=&nbsp;true&nbsp;*)</span><br/>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="id" title="tactic">unfold</span> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#not"><span class="id" title="definition">not</span></a> <span class="id" title="keyword">in</span> <span class="id" title="var">H</span>.<br/>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="id" title="tactic">apply</span> <a class="idref" href="Logic.html#ex_falso_quodlibet"><span class="id" title="lemma">ex_falso_quodlibet</span></a>.<br/>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="id" title="tactic">apply</span> <span class="id" title="var">H</span>. <span class="id" title="tactic">reflexivity</span>.<br/>
&nbsp;&nbsp;- <span class="comment">(*&nbsp;b&nbsp;=&nbsp;false&nbsp;*)</span><br/>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="id" title="tactic">reflexivity</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>

<div class="doc">
Since reasoning with <span class="inlinecode"><span class="id" title="var">ex_falso_quodlibet</span></span> is quite common, Coq
    provides a built-in tactic, <span class="inlinecode"><span class="id" title="var">exfalso</span></span>, for applying it. 
</div>
<div class="code">

<span class="id" title="keyword">Theorem</span> <a id="not_true_is_false'" class="idref" href="#not_true_is_false'"><span class="id" title="lemma">not_true_is_false'</span></a> : <span class="id" title="keyword">∀</span> <a id="b:52" class="idref" href="#b:52"><span class="id" title="binder">b</span></a> : <a class="idref" href="Basics.html#bool"><span class="id" title="inductive">bool</span></a>,<br/>
&nbsp;&nbsp;<a class="idref" href="Logic.html#b:52"><span class="id" title="variable">b</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'&lt;&gt;'_x"><span class="id" title="notation">≠</span></a> <a class="idref" href="Basics.html#true"><span class="id" title="constructor">true</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="Logic.html#b:52"><span class="id" title="variable">b</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Basics.html#false"><span class="id" title="constructor">false</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">intros</span> [] <span class="id" title="var">H</span>. <span class="comment">(*&nbsp;note&nbsp;implicit&nbsp;<span class="inlinecode"><span class="id" title="tactic">destruct</span></span> <span class="inlinecode"><span class="id" title="var">b</span></span>&nbsp;here&nbsp;*)</span><br/>
&nbsp;&nbsp;- <span class="comment">(*&nbsp;b&nbsp;=&nbsp;true&nbsp;*)</span><br/>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="id" title="tactic">unfold</span> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#not"><span class="id" title="definition">not</span></a> <span class="id" title="keyword">in</span> <span class="id" title="var">H</span>.<br/>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="id" title="var">exfalso</span>. <span class="comment">(*&nbsp;&lt;===&nbsp;*)</span><br/>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="id" title="tactic">apply</span> <span class="id" title="var">H</span>. <span class="id" title="tactic">reflexivity</span>.<br/>
&nbsp;&nbsp;- <span class="comment">(*&nbsp;b&nbsp;=&nbsp;false&nbsp;*)</span> <span class="id" title="tactic">reflexivity</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>

<div class="doc">
<a id="lab181"></a><h2 class="section">Truth</h2>

<div class="paragraph"> </div>

 Besides <span class="inlinecode"><span class="id" title="var">False</span></span>, Coq's standard library also defines <span class="inlinecode"><span class="id" title="var">True</span></span>, a
    proposition that is trivially true. To prove it, we use the
    predefined constant <span class="inlinecode"><span class="id" title="var">I</span></span> <span class="inlinecode">:</span> <span class="inlinecode"><span class="id" title="var">True</span></span>: 
</div>
<div class="code">

<span class="id" title="keyword">Lemma</span> <a id="True_is_true" class="idref" href="#True_is_true"><span class="id" title="lemma">True_is_true</span></a> : <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#True"><span class="id" title="inductive">True</span></a>.<br/>
<span class="id" title="keyword">Proof</span>. <span class="id" title="tactic">apply</span> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#I"><span class="id" title="constructor">I</span></a>. <span class="id" title="keyword">Qed</span>.<br/>
</div>

<div class="doc">
Unlike <span class="inlinecode"><span class="id" title="var">False</span></span>, which is used extensively, <span class="inlinecode"><span class="id" title="var">True</span></span> is used
    relatively rarely, since it is trivial (and therefore
    uninteresting) to prove as a goal, and conversely it provides no
    useful information as a hypothesis.  But it can be quite useful when defining complex <span class="inlinecode"><span class="id" title="keyword">Prop</span></span>s using
    conditionals or as a parameter to higher-order <span class="inlinecode"><span class="id" title="keyword">Prop</span></span>s.  We will
    see examples later on. 
<div class="paragraph"> </div>

 As an example, we can demonstrate how to achieve a similar effect
    as the <span class="inlinecode"><span class="id" title="tactic">discriminate</span></span> tactic, without using it. 
<div class="paragraph"> </div>

 Pattern-matching lets us do different things for different
    constructors.  If the result of applying two different
    constructors were hypothetically equal, then we could use <span class="inlinecode"><span class="id" title="keyword">match</span></span>
    to convert an unprovable statement (like <span class="inlinecode"><span class="id" title="var">False</span></span>) to one that is
    provable (like <span class="inlinecode"><span class="id" title="var">True</span></span>). 
</div>
<div class="code">

<span class="id" title="keyword">Definition</span> <a id="disc_fn" class="idref" href="#disc_fn"><span class="id" title="definition">disc_fn</span></a> (<a id="n:53" class="idref" href="#n:53"><span class="id" title="binder">n</span></a>: <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#nat"><span class="id" title="inductive">nat</span></a>) : <span class="id" title="keyword">Prop</span> :=<br/>
&nbsp;&nbsp;<span class="id" title="keyword">match</span> <a class="idref" href="Logic.html#n:53"><span class="id" title="variable">n</span></a> <span class="id" title="keyword">with</span><br/>
&nbsp;&nbsp;| <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#O"><span class="id" title="constructor">O</span></a> ⇒ <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#True"><span class="id" title="inductive">True</span></a><br/>
&nbsp;&nbsp;| <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#S"><span class="id" title="constructor">S</span></a> <span class="id" title="var">_</span> ⇒ <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#False"><span class="id" title="inductive">False</span></a><br/>
&nbsp;&nbsp;<span class="id" title="keyword">end</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Theorem</span> <a id="disc" class="idref" href="#disc"><span class="id" title="lemma">disc</span></a> : <span class="id" title="keyword">∀</span> <a id="n:55" class="idref" href="#n:55"><span class="id" title="binder">n</span></a>, <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#63a68285c81db8f9bc456233bb9ed181"><span class="id" title="notation">¬</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#63a68285c81db8f9bc456233bb9ed181"><span class="id" title="notation">(</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#O"><span class="id" title="constructor">O</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#S"><span class="id" title="constructor">S</span></a> <a class="idref" href="Logic.html#n:55"><span class="id" title="variable">n</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#63a68285c81db8f9bc456233bb9ed181"><span class="id" title="notation">)</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">intros</span> <span class="id" title="var">n</span> <span class="id" title="var">H<sub>1</sub></span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">assert</span> (<span class="id" title="var">H<sub>2</sub></span> : <a class="idref" href="Logic.html#disc_fn"><span class="id" title="definition">disc_fn</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#O"><span class="id" title="constructor">O</span></a>). { <span class="id" title="tactic">simpl</span>. <span class="id" title="tactic">apply</span> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#I"><span class="id" title="constructor">I</span></a>. }<br/>
&nbsp;&nbsp;<span class="id" title="tactic">rewrite</span> <span class="id" title="var">H<sub>1</sub></span> <span class="id" title="keyword">in</span> <span class="id" title="var">H<sub>2</sub></span>. <span class="id" title="tactic">simpl</span> <span class="id" title="keyword">in</span> <span class="id" title="var">H<sub>2</sub></span>. <span class="id" title="tactic">apply</span> <span class="id" title="var">H<sub>2</sub></span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>

<div class="doc">
To generalize this to other constructors, we simply have to
    provide the appropriate generalization of <span class="inlinecode"><span class="id" title="var">disc_fn</span></span>. To generalize
    it to other conclusions, we can use <span class="inlinecode"><span class="id" title="var">exfalso</span></span> to replace them. But
    the built-in <span class="inlinecode"><span class="id" title="tactic">discriminate</span></span> takes care of all this for us. 
<div class="paragraph"> </div>

<a id="lab182"></a><h2 class="section">Logical Equivalence</h2>

<div class="paragraph"> </div>

 The handy "if and only if" connective, which asserts that two
    propositions have the same truth value, is simply the conjunction
    of two implications. 
</div>
<div class="code">

<span class="id" title="keyword">Module</span> <a id="MyIff" class="idref" href="#MyIff"><span class="id" title="module">MyIff</span></a>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Definition</span> <a id="MyIff.iff" class="idref" href="#MyIff.iff"><span class="id" title="definition">iff</span></a> (<a id="P:56" class="idref" href="#P:56"><span class="id" title="binder">P</span></a> <a id="Q:57" class="idref" href="#Q:57"><span class="id" title="binder">Q</span></a> : <span class="id" title="keyword">Prop</span>) := <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#ba2b0e492d2b4675a0acf3ea92aabadd"><span class="id" title="notation">(</span></a><a class="idref" href="Logic.html#P:56"><span class="id" title="variable">P</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="Logic.html#Q:57"><span class="id" title="variable">Q</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#ba2b0e492d2b4675a0acf3ea92aabadd"><span class="id" title="notation">)</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#ba2b0e492d2b4675a0acf3ea92aabadd"><span class="id" title="notation">∧</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#ba2b0e492d2b4675a0acf3ea92aabadd"><span class="id" title="notation">(</span></a><a class="idref" href="Logic.html#Q:57"><span class="id" title="variable">Q</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="Logic.html#P:56"><span class="id" title="variable">P</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#ba2b0e492d2b4675a0acf3ea92aabadd"><span class="id" title="notation">)</span></a>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Notation</span> <a id="MyIff.::type_scope:x_'&lt;-&gt;'_x" class="idref" href="#MyIff.::type_scope:x_'&lt;-&gt;'_x"><span class="id" title="notation">&quot;</span></a>P &lt;<span class="nowrap"><span style='font-size:85%;'><span style='vertical-align:5%;'><span style='letter-spacing:-.2em;'>-</span></span>&gt;</span></span> Q" := (<a class="idref" href="Logic.html#MyIff.iff"><span class="id" title="definition">iff</span></a> <span class="id" title="var">P</span> <span class="id" title="var">Q</span>)<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(<span class="id" title="tactic">at</span> <span class="id" title="keyword">level</span> 95, <span class="id" title="keyword">no</span> <span class="id" title="keyword">associativity</span>)<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: <span class="id" title="var">type_scope</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">End</span> <a class="idref" href="Logic.html#MyIff"><span class="id" title="module">MyIff</span></a>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Theorem</span> <a id="iff_sym" class="idref" href="#iff_sym"><span class="id" title="lemma">iff_sym</span></a> : <span class="id" title="keyword">∀</span> <a id="P:58" class="idref" href="#P:58"><span class="id" title="binder">P</span></a> <a id="Q:59" class="idref" href="#Q:59"><span class="id" title="binder">Q</span></a> : <span class="id" title="keyword">Prop</span>,<br/>
&nbsp;&nbsp;<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">(</span></a><a class="idref" href="Logic.html#P:58"><span class="id" title="variable">P</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'&lt;-&gt;'_x"><span class="id" title="notation">↔</span></a> <a class="idref" href="Logic.html#Q:59"><span class="id" title="variable">Q</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">)</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">(</span></a><a class="idref" href="Logic.html#Q:59"><span class="id" title="variable">Q</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'&lt;-&gt;'_x"><span class="id" title="notation">↔</span></a> <a class="idref" href="Logic.html#P:58"><span class="id" title="variable">P</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">)</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="comment">(*&nbsp;WORKED&nbsp;IN&nbsp;CLASS&nbsp;*)</span><br/>
&nbsp;&nbsp;<span class="id" title="tactic">intros</span> <span class="id" title="var">P</span> <span class="id" title="var">Q</span> [<span class="id" title="var">HAB</span> <span class="id" title="var">HBA</span>].<br/>
&nbsp;&nbsp;<span class="id" title="tactic">split</span>.<br/>
&nbsp;&nbsp;- <span class="comment">(*&nbsp;<span class="nowrap"><span style='font-size:85%;'><span style='vertical-align:5%;'><span style='letter-spacing:-.2em;'>-</span></span>&gt;</span></span>&nbsp;*)</span> <span class="id" title="tactic">apply</span> <span class="id" title="var">HBA</span>.<br/>
&nbsp;&nbsp;- <span class="comment">(*&nbsp;&lt;-&nbsp;*)</span> <span class="id" title="tactic">apply</span> <span class="id" title="var">HAB</span>. <span class="id" title="keyword">Qed</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Lemma</span> <a id="not_true_iff_false" class="idref" href="#not_true_iff_false"><span class="id" title="lemma">not_true_iff_false</span></a> : <span class="id" title="keyword">∀</span> <a id="b:60" class="idref" href="#b:60"><span class="id" title="binder">b</span></a>,<br/>
&nbsp;&nbsp;<a class="idref" href="Logic.html#b:60"><span class="id" title="variable">b</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'&lt;&gt;'_x"><span class="id" title="notation">≠</span></a> <a class="idref" href="Basics.html#true"><span class="id" title="constructor">true</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'&lt;-&gt;'_x"><span class="id" title="notation">↔</span></a> <a class="idref" href="Logic.html#b:60"><span class="id" title="variable">b</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Basics.html#false"><span class="id" title="constructor">false</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="comment">(*&nbsp;WORKED&nbsp;IN&nbsp;CLASS&nbsp;*)</span><br/>
&nbsp;&nbsp;<span class="id" title="tactic">intros</span> <span class="id" title="var">b</span>. <span class="id" title="tactic">split</span>.<br/>
&nbsp;&nbsp;- <span class="comment">(*&nbsp;<span class="nowrap"><span style='font-size:85%;'><span style='vertical-align:5%;'><span style='letter-spacing:-.2em;'>-</span></span>&gt;</span></span>&nbsp;*)</span> <span class="id" title="tactic">apply</span> <a class="idref" href="Logic.html#not_true_is_false"><span class="id" title="lemma">not_true_is_false</span></a>.<br/>
&nbsp;&nbsp;- <span class="comment">(*&nbsp;&lt;-&nbsp;*)</span><br/>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="id" title="tactic">intros</span> <span class="id" title="var">H</span>. <span class="id" title="tactic">rewrite</span> <span class="id" title="var">H</span>. <span class="id" title="tactic">intros</span> <span class="id" title="var">H'</span>. <span class="id" title="tactic">discriminate</span> <span class="id" title="var">H'</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/><hr class='doublespaceincode'/>
</div>

<div class="doc">
<a id="lab184"></a><h4 class="section">Exercise: 3 stars, standard (or_distributes_over_and)</h4>

</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <a id="or_distributes_over_and" class="idref" href="#or_distributes_over_and"><span class="id" title="lemma">or_distributes_over_and</span></a> : <span class="id" title="keyword">∀</span> <a id="P:65" class="idref" href="#P:65"><span class="id" title="binder">P</span></a> <a id="Q:66" class="idref" href="#Q:66"><span class="id" title="binder">Q</span></a> <a id="R:67" class="idref" href="#R:67"><span class="id" title="binder">R</span></a> : <span class="id" title="keyword">Prop</span>,<br/>
&nbsp;&nbsp;<a class="idref" href="Logic.html#P:65"><span class="id" title="variable">P</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#f031fe1957c4a4a8e217aa46af2b4e<sub>25</sub>"><span class="id" title="notation">∨</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#f031fe1957c4a4a8e217aa46af2b4e<sub>25</sub>"><span class="id" title="notation">(</span></a><a class="idref" href="Logic.html#Q:66"><span class="id" title="variable">Q</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#ba2b0e492d2b4675a0acf3ea92aabadd"><span class="id" title="notation">∧</span></a> <a class="idref" href="Logic.html#R:67"><span class="id" title="variable">R</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#f031fe1957c4a4a8e217aa46af2b4e<sub>25</sub>"><span class="id" title="notation">)</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'&lt;-&gt;'_x"><span class="id" title="notation">↔</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#ba2b0e492d2b4675a0acf3ea92aabadd"><span class="id" title="notation">(</span></a><a class="idref" href="Logic.html#P:65"><span class="id" title="variable">P</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#f031fe1957c4a4a8e217aa46af2b4e<sub>25</sub>"><span class="id" title="notation">∨</span></a> <a class="idref" href="Logic.html#Q:66"><span class="id" title="variable">Q</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#ba2b0e492d2b4675a0acf3ea92aabadd"><span class="id" title="notation">)</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#ba2b0e492d2b4675a0acf3ea92aabadd"><span class="id" title="notation">∧</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#ba2b0e492d2b4675a0acf3ea92aabadd"><span class="id" title="notation">(</span></a><a class="idref" href="Logic.html#P:65"><span class="id" title="variable">P</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#f031fe1957c4a4a8e217aa46af2b4e<sub>25</sub>"><span class="id" title="notation">∨</span></a> <a class="idref" href="Logic.html#R:67"><span class="id" title="variable">R</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#ba2b0e492d2b4675a0acf3ea92aabadd"><span class="id" title="notation">)</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="comment">(*&nbsp;FILL&nbsp;IN&nbsp;HERE&nbsp;*)</span> <span class="id" title="var">Admitted</span>.<br/>
<font size=-2>&#9744;</font>
</div>

<div class="doc"> 
<div class="paragraph"> </div>

<a id="lab185"></a><h2 class="section">Setoids and Logical Equivalence</h2>

<div class="paragraph"> </div>

 Some of Coq's tactics treat <span class="inlinecode"><span class="id" title="var">iff</span></span> statements specially, avoiding
    the need for some low-level proof-state manipulation.  In
    particular, <span class="inlinecode"><span class="id" title="tactic">rewrite</span></span> and <span class="inlinecode"><span class="id" title="tactic">reflexivity</span></span> can be used with <span class="inlinecode"><span class="id" title="var">iff</span></span>
    statements, not just equalities.  To enable this behavior, we have
    to import the Coq library that supports it: 
</div>
<div class="code">

<span class="id" title="keyword">From</span> <span class="id" title="var">Coq</span> <span class="id" title="keyword">Require</span> <span class="id" title="keyword">Import</span> <a class="idref" href="http://coq.inria.fr/library//Coq.Setoids.Setoid.html#"><span class="id" title="library">Setoids.Setoid</span></a>.<br/>
</div>

<div class="doc">
A "setoid" is a set equipped with an equivalence relation,
    that is, a relation that is reflexive, symmetric, and transitive.
    When two elements of a set are equivalent according to the
    relation, <span class="inlinecode"><span class="id" title="tactic">rewrite</span></span> can be used to replace one element with the
    other. We've seen that already with the equality relation <span class="inlinecode">=</span> in
    Coq: when <span class="inlinecode"><span class="id" title="var">x</span></span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" title="var">y</span></span>, we can use <span class="inlinecode"><span class="id" title="tactic">rewrite</span></span> to replace <span class="inlinecode"><span class="id" title="var">x</span></span> with <span class="inlinecode"><span class="id" title="var">y</span></span>,
    or vice-versa.

<div class="paragraph"> </div>

    Similarly, the logical equivalence relation <span class="inlinecode">↔</span> is reflexive,
    symmetric, and transitive, so we can use it to replace one part of
    a proposition with another: if <span class="inlinecode"><span class="id" title="var">P</span></span> <span class="inlinecode">↔</span> <span class="inlinecode"><span class="id" title="var">Q</span></span>, then we can use
    <span class="inlinecode"><span class="id" title="tactic">rewrite</span></span> to replace <span class="inlinecode"><span class="id" title="var">P</span></span> with <span class="inlinecode"><span class="id" title="var">Q</span></span>, or vice-versa. 
<div class="paragraph"> </div>

 Here is a simple example demonstrating how these tactics work with
    <span class="inlinecode"><span class="id" title="var">iff</span></span>.  First, let's prove a couple of basic iff equivalences. 
</div>
<div class="code">

<span class="id" title="keyword">Lemma</span> <a id="mul_eq_0" class="idref" href="#mul_eq_0"><span class="id" title="lemma">mul_eq_0</span></a> : <span class="id" title="keyword">∀</span> <a id="n:68" class="idref" href="#n:68"><span class="id" title="binder">n</span></a> <a id="m:69" class="idref" href="#m:69"><span class="id" title="binder">m</span></a>, <a class="idref" href="Logic.html#n:68"><span class="id" title="variable">n</span></a> <a class="idref" href="Basics.html#ea2ff3d561159081cea6fb2e8113cc<sub>54</sub>"><span class="id" title="notation">×</span></a> <a class="idref" href="Logic.html#m:69"><span class="id" title="variable">m</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> 0 <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'&lt;-&gt;'_x"><span class="id" title="notation">↔</span></a> <a class="idref" href="Logic.html#n:68"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> 0 <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#f031fe1957c4a4a8e217aa46af2b4e<sub>25</sub>"><span class="id" title="notation">∨</span></a> <a class="idref" href="Logic.html#m:69"><span class="id" title="variable">m</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> 0.<br/>
<div class="togglescript" id="proofcontrol1" onclick="toggleDisplay('proof1');toggleDisplay('proofcontrol1')"><span class="show"></span></div>
<div class="proofscript" id="proof1" onclick="toggleDisplay('proof1');toggleDisplay('proofcontrol1')">
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">split</span>.<br/>
&nbsp;&nbsp;- <span class="id" title="tactic">apply</span> <a class="idref" href="Logic.html#mult_is_O"><span class="id" title="axiom">mult_is_O</span></a>.<br/>
&nbsp;&nbsp;- <span class="id" title="tactic">apply</span> <a class="idref" href="Logic.html#factor_is_O"><span class="id" title="lemma">factor_is_O</span></a>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>

<br/>
<span class="id" title="keyword">Theorem</span> <a id="or_assoc" class="idref" href="#or_assoc"><span class="id" title="lemma">or_assoc</span></a> :<br/>
&nbsp;&nbsp;<span class="id" title="keyword">∀</span> <a id="P:70" class="idref" href="#P:70"><span class="id" title="binder">P</span></a> <a id="Q:71" class="idref" href="#Q:71"><span class="id" title="binder">Q</span></a> <a id="R:72" class="idref" href="#R:72"><span class="id" title="binder">R</span></a> : <span class="id" title="keyword">Prop</span>, <a class="idref" href="Logic.html#P:70"><span class="id" title="variable">P</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#f031fe1957c4a4a8e217aa46af2b4e<sub>25</sub>"><span class="id" title="notation">∨</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#f031fe1957c4a4a8e217aa46af2b4e<sub>25</sub>"><span class="id" title="notation">(</span></a><a class="idref" href="Logic.html#Q:71"><span class="id" title="variable">Q</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#f031fe1957c4a4a8e217aa46af2b4e<sub>25</sub>"><span class="id" title="notation">∨</span></a> <a class="idref" href="Logic.html#R:72"><span class="id" title="variable">R</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#f031fe1957c4a4a8e217aa46af2b4e<sub>25</sub>"><span class="id" title="notation">)</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'&lt;-&gt;'_x"><span class="id" title="notation">↔</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#f031fe1957c4a4a8e217aa46af2b4e<sub>25</sub>"><span class="id" title="notation">(</span></a><a class="idref" href="Logic.html#P:70"><span class="id" title="variable">P</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#f031fe1957c4a4a8e217aa46af2b4e<sub>25</sub>"><span class="id" title="notation">∨</span></a> <a class="idref" href="Logic.html#Q:71"><span class="id" title="variable">Q</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#f031fe1957c4a4a8e217aa46af2b4e<sub>25</sub>"><span class="id" title="notation">)</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#f031fe1957c4a4a8e217aa46af2b4e<sub>25</sub>"><span class="id" title="notation">∨</span></a> <a class="idref" href="Logic.html#R:72"><span class="id" title="variable">R</span></a>.<br/>
<div class="togglescript" id="proofcontrol2" onclick="toggleDisplay('proof2');toggleDisplay('proofcontrol2')"><span class="show"></span></div>
<div class="proofscript" id="proof2" onclick="toggleDisplay('proof2');toggleDisplay('proofcontrol2')">
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">intros</span> <span class="id" title="var">P</span> <span class="id" title="var">Q</span> <span class="id" title="var">R</span>. <span class="id" title="tactic">split</span>.<br/>
&nbsp;&nbsp;- <span class="id" title="tactic">intros</span> [<span class="id" title="var">H</span> | [<span class="id" title="var">H</span> | <span class="id" title="var">H</span>]].<br/>
&nbsp;&nbsp;&nbsp;&nbsp;+ <span class="id" title="tactic">left</span>. <span class="id" title="tactic">left</span>. <span class="id" title="tactic">apply</span> <span class="id" title="var">H</span>.<br/>
&nbsp;&nbsp;&nbsp;&nbsp;+ <span class="id" title="tactic">left</span>. <span class="id" title="tactic">right</span>. <span class="id" title="tactic">apply</span> <span class="id" title="var">H</span>.<br/>
&nbsp;&nbsp;&nbsp;&nbsp;+ <span class="id" title="tactic">right</span>. <span class="id" title="tactic">apply</span> <span class="id" title="var">H</span>.<br/>
&nbsp;&nbsp;- <span class="id" title="tactic">intros</span> [[<span class="id" title="var">H</span> | <span class="id" title="var">H</span>] | <span class="id" title="var">H</span>].<br/>
&nbsp;&nbsp;&nbsp;&nbsp;+ <span class="id" title="tactic">left</span>. <span class="id" title="tactic">apply</span> <span class="id" title="var">H</span>.<br/>
&nbsp;&nbsp;&nbsp;&nbsp;+ <span class="id" title="tactic">right</span>. <span class="id" title="tactic">left</span>. <span class="id" title="tactic">apply</span> <span class="id" title="var">H</span>.<br/>
&nbsp;&nbsp;&nbsp;&nbsp;+ <span class="id" title="tactic">right</span>. <span class="id" title="tactic">right</span>. <span class="id" title="tactic">apply</span> <span class="id" title="var">H</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>
</div>

<div class="doc">
We can now use these facts with <span class="inlinecode"><span class="id" title="tactic">rewrite</span></span> and <span class="inlinecode"><span class="id" title="tactic">reflexivity</span></span>
    to give smooth proofs of statements involving equivalences.  For
    example, here is a ternary version of the previous <span class="inlinecode"><span class="id" title="var">mult_0</span></span>
    result: 
</div>
<div class="code">

<span class="id" title="keyword">Lemma</span> <a id="mul_eq_0_ternary" class="idref" href="#mul_eq_0_ternary"><span class="id" title="lemma">mul_eq_0_ternary</span></a> :<br/>
&nbsp;&nbsp;<span class="id" title="keyword">∀</span> <a id="n:73" class="idref" href="#n:73"><span class="id" title="binder">n</span></a> <a id="m:74" class="idref" href="#m:74"><span class="id" title="binder">m</span></a> <a id="p:75" class="idref" href="#p:75"><span class="id" title="binder">p</span></a>, <a class="idref" href="Logic.html#n:73"><span class="id" title="variable">n</span></a> <a class="idref" href="Basics.html#ea2ff3d561159081cea6fb2e8113cc<sub>54</sub>"><span class="id" title="notation">×</span></a> <a class="idref" href="Logic.html#m:74"><span class="id" title="variable">m</span></a> <a class="idref" href="Basics.html#ea2ff3d561159081cea6fb2e8113cc<sub>54</sub>"><span class="id" title="notation">×</span></a> <a class="idref" href="Logic.html#p:75"><span class="id" title="variable">p</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> 0 <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'&lt;-&gt;'_x"><span class="id" title="notation">↔</span></a> <a class="idref" href="Logic.html#n:73"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> 0 <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#f031fe1957c4a4a8e217aa46af2b4e<sub>25</sub>"><span class="id" title="notation">∨</span></a> <a class="idref" href="Logic.html#m:74"><span class="id" title="variable">m</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> 0 <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#f031fe1957c4a4a8e217aa46af2b4e<sub>25</sub>"><span class="id" title="notation">∨</span></a> <a class="idref" href="Logic.html#p:75"><span class="id" title="variable">p</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> 0.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">intros</span> <span class="id" title="var">n</span> <span class="id" title="var">m</span> <span class="id" title="var">p</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">rewrite</span> <a class="idref" href="Logic.html#mul_eq_0"><span class="id" title="lemma">mul_eq_0</span></a>. <span class="id" title="tactic">rewrite</span> <a class="idref" href="Logic.html#mul_eq_0"><span class="id" title="lemma">mul_eq_0</span></a>. <span class="id" title="tactic">rewrite</span> <a class="idref" href="Logic.html#or_assoc"><span class="id" title="lemma">or_assoc</span></a>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">reflexivity</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>

<div class="doc">
The <span class="inlinecode"><span class="id" title="tactic">apply</span></span> tactic can also be used with <span class="inlinecode">↔</span>. When given an
    equivalence as its argument, <span class="inlinecode"><span class="id" title="tactic">apply</span></span> tries to guess which
    direction of the equivalence will be useful. 
</div>
<div class="code">

<span class="id" title="keyword">Lemma</span> <a id="apply_iff_example" class="idref" href="#apply_iff_example"><span class="id" title="lemma">apply_iff_example</span></a> :<br/>
&nbsp;&nbsp;<span class="id" title="keyword">∀</span> <a id="n:76" class="idref" href="#n:76"><span class="id" title="binder">n</span></a> <a id="m:77" class="idref" href="#m:77"><span class="id" title="binder">m</span></a> : <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#nat"><span class="id" title="inductive">nat</span></a>, <a class="idref" href="Logic.html#n:76"><span class="id" title="variable">n</span></a> <a class="idref" href="Basics.html#ea2ff3d561159081cea6fb2e8113cc<sub>54</sub>"><span class="id" title="notation">×</span></a> <a class="idref" href="Logic.html#m:77"><span class="id" title="variable">m</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> 0 <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="Logic.html#n:76"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> 0 <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#f031fe1957c4a4a8e217aa46af2b4e<sub>25</sub>"><span class="id" title="notation">∨</span></a> <a class="idref" href="Logic.html#m:77"><span class="id" title="variable">m</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> 0.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">intros</span> <span class="id" title="var">n</span> <span class="id" title="var">m</span> <span class="id" title="var">H</span>. <span class="id" title="tactic">apply</span> <a class="idref" href="Logic.html#mul_eq_0"><span class="id" title="lemma">mul_eq_0</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">H</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>

<div class="doc">
<a id="lab186"></a><h2 class="section">Existential Quantification</h2>

<div class="paragraph"> </div>

 Another important logical connective is <i>existential
    quantification</i>.  To say that there is some <span class="inlinecode"><span class="id" title="var">x</span></span> of type <span class="inlinecode"><span class="id" title="var">T</span></span> such
    that some property <span class="inlinecode"><span class="id" title="var">P</span></span> holds of <span class="inlinecode"><span class="id" title="var">x</span></span>, we write <span class="inlinecode"><span class="id" title="tactic">∃</span></span> <span class="inlinecode"><span class="id" title="var">x</span></span> <span class="inlinecode">:</span> <span class="inlinecode"><span class="id" title="var">T</span>,</span>
    <span class="inlinecode"><span class="id" title="var">P</span></span>. As with <span class="inlinecode"><span class="id" title="keyword">∀</span></span>, the type annotation <span class="inlinecode">:</span> <span class="inlinecode"><span class="id" title="var">T</span></span> can be omitted if
    Coq is able to infer from the context what the type of <span class="inlinecode"><span class="id" title="var">x</span></span> should
    be. 
<div class="paragraph"> </div>

 To prove a statement of the form <span class="inlinecode"><span class="id" title="tactic">∃</span></span> <span class="inlinecode"><span class="id" title="var">x</span>,</span> <span class="inlinecode"><span class="id" title="var">P</span></span>, we must show that
    <span class="inlinecode"><span class="id" title="var">P</span></span> holds for some specific choice of value for <span class="inlinecode"><span class="id" title="var">x</span></span>, known as the
    <i>witness</i> of the existential.  This is done in two steps: First,
    we explicitly tell Coq which witness <span class="inlinecode"><span class="id" title="var">t</span></span> we have in mind by
    invoking the tactic <span class="inlinecode"><span class="id" title="tactic">∃</span></span> <span class="inlinecode"><span class="id" title="var">t</span></span>.  Then we prove that <span class="inlinecode"><span class="id" title="var">P</span></span> holds after
    all occurrences of <span class="inlinecode"><span class="id" title="var">x</span></span> are replaced by <span class="inlinecode"><span class="id" title="var">t</span></span>. 
</div>
<div class="code">

<span class="id" title="keyword">Definition</span> <a id="Even" class="idref" href="#Even"><span class="id" title="definition">Even</span></a> <a id="x:78" class="idref" href="#x:78"><span class="id" title="binder">x</span></a> := <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#a883bdd010993579f99d60b3775bcf54"><span class="id" title="notation">∃</span></a> <a id="n:79" class="idref" href="#n:79"><span class="id" title="binder">n</span></a> : <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#nat"><span class="id" title="inductive">nat</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#a883bdd010993579f99d60b3775bcf54"><span class="id" title="notation">,</span></a> <a class="idref" href="Logic.html#x:78"><span class="id" title="variable">x</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Induction.html#double"><span class="id" title="definition">double</span></a> <a class="idref" href="Logic.html#n:79"><span class="id" title="variable">n</span></a>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Lemma</span> <a id="four_is_even" class="idref" href="#four_is_even"><span class="id" title="lemma">four_is_even</span></a> : <a class="idref" href="Logic.html#Even"><span class="id" title="definition">Even</span></a> 4.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">unfold</span> <a class="idref" href="Logic.html#Even"><span class="id" title="definition">Even</span></a>. <span class="id" title="tactic">∃</span> 2. <span class="id" title="tactic">reflexivity</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>

<div class="doc">
Conversely, if we have an existential hypothesis <span class="inlinecode"><span class="id" title="tactic">∃</span></span> <span class="inlinecode"><span class="id" title="var">x</span>,</span> <span class="inlinecode"><span class="id" title="var">P</span></span> in
    the context, we can destruct it to obtain a witness <span class="inlinecode"><span class="id" title="var">x</span></span> and a
    hypothesis stating that <span class="inlinecode"><span class="id" title="var">P</span></span> holds of <span class="inlinecode"><span class="id" title="var">x</span></span>. 
</div>
<div class="code">

<span class="id" title="keyword">Theorem</span> <a id="exists_example_2" class="idref" href="#exists_example_2"><span class="id" title="lemma">exists_example_2</span></a> : <span class="id" title="keyword">∀</span> <a id="n:80" class="idref" href="#n:80"><span class="id" title="binder">n</span></a>,<br/>
&nbsp;&nbsp;<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">(</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#a883bdd010993579f99d60b3775bcf54"><span class="id" title="notation">∃</span></a> <a id="m:81" class="idref" href="#m:81"><span class="id" title="binder">m</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#a883bdd010993579f99d60b3775bcf54"><span class="id" title="notation">,</span></a> <a class="idref" href="Logic.html#n:80"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> 4 <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> <a class="idref" href="Logic.html#m:81"><span class="id" title="variable">m</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">)</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a><br/>
&nbsp;&nbsp;<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">(</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#a883bdd010993579f99d60b3775bcf54"><span class="id" title="notation">∃</span></a> <a id="o:82" class="idref" href="#o:82"><span class="id" title="binder">o</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#a883bdd010993579f99d60b3775bcf54"><span class="id" title="notation">,</span></a> <a class="idref" href="Logic.html#n:80"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> 2 <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> <a class="idref" href="Logic.html#o:82"><span class="id" title="variable">o</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">)</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="comment">(*&nbsp;WORKED&nbsp;IN&nbsp;CLASS&nbsp;*)</span><br/>
&nbsp;&nbsp;<span class="id" title="tactic">intros</span> <span class="id" title="var">n</span> [<span class="id" title="var">m</span> <span class="id" title="var">Hm</span>]. <span class="comment">(*&nbsp;note&nbsp;implicit&nbsp;<span class="inlinecode"><span class="id" title="tactic">destruct</span></span>&nbsp;here&nbsp;*)</span><br/>
&nbsp;&nbsp;<span class="id" title="tactic">∃</span> (2 <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> <span class="id" title="var">m</span>).<br/>
&nbsp;&nbsp;<span class="id" title="tactic">apply</span> <span class="id" title="var">Hm</span>. <span class="id" title="keyword">Qed</span>.<br/>
</div>

<div class="doc">
<a id="lab187"></a><h4 class="section">Exercise: 1 star, standard, especially useful (dist_not_exists)</h4>
 Prove that "<span class="inlinecode"><span class="id" title="var">P</span></span> holds for all <span class="inlinecode"><span class="id" title="var">x</span></span>" implies "there is no <span class="inlinecode"><span class="id" title="var">x</span></span> for
    which <span class="inlinecode"><span class="id" title="var">P</span></span> does not hold."  (Hint: <span class="inlinecode"><span class="id" title="tactic">destruct</span></span> <span class="inlinecode"><span class="id" title="var">H</span></span> <span class="inlinecode"><span class="id" title="keyword">as</span></span> <span class="inlinecode">[<span class="id" title="var">x</span></span> <span class="inlinecode"><span class="id" title="var">E</span>]</span> works on
    existential assumptions!)  
</div>
<div class="code">

<span class="id" title="keyword">Theorem</span> <a id="dist_not_exists" class="idref" href="#dist_not_exists"><span class="id" title="lemma">dist_not_exists</span></a> : <span class="id" title="keyword">∀</span> (<a id="X:83" class="idref" href="#X:83"><span class="id" title="binder">X</span></a>:<span class="id" title="keyword">Type</span>) (<a id="P:84" class="idref" href="#P:84"><span class="id" title="binder">P</span></a> : <a class="idref" href="Logic.html#X:83"><span class="id" title="variable">X</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <span class="id" title="keyword">Prop</span>),<br/>
&nbsp;&nbsp;<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">(</span></a><span class="id" title="keyword">∀</span> <a id="x:85" class="idref" href="#x:85"><span class="id" title="binder">x</span></a>, <a class="idref" href="Logic.html#P:84"><span class="id" title="variable">P</span></a> <a class="idref" href="Logic.html#x:85"><span class="id" title="variable">x</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">)</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#63a68285c81db8f9bc456233bb9ed181"><span class="id" title="notation">¬</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#63a68285c81db8f9bc456233bb9ed181"><span class="id" title="notation">(</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#a883bdd010993579f99d60b3775bcf54"><span class="id" title="notation">∃</span></a> <a id="x:86" class="idref" href="#x:86"><span class="id" title="binder">x</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#a883bdd010993579f99d60b3775bcf54"><span class="id" title="notation">,</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#63a68285c81db8f9bc456233bb9ed181"><span class="id" title="notation">¬</span></a> <a class="idref" href="Logic.html#P:84"><span class="id" title="variable">P</span></a> <a class="idref" href="Logic.html#x:86"><span class="id" title="variable">x</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#63a68285c81db8f9bc456233bb9ed181"><span class="id" title="notation">)</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="comment">(*&nbsp;FILL&nbsp;IN&nbsp;HERE&nbsp;*)</span> <span class="id" title="var">Admitted</span>.<br/>
<font size=-2>&#9744;</font>
</div>

<div class="doc"> 
<div class="paragraph"> </div>

<a id="lab188"></a><h4 class="section">Exercise: 2 stars, standard (dist_exists_or)</h4>
 Prove that existential quantification distributes over
    disjunction. 
</div>
<div class="code">

<span class="id" title="keyword">Theorem</span> <a id="dist_exists_or" class="idref" href="#dist_exists_or"><span class="id" title="lemma">dist_exists_or</span></a> : <span class="id" title="keyword">∀</span> (<a id="X:87" class="idref" href="#X:87"><span class="id" title="binder">X</span></a>:<span class="id" title="keyword">Type</span>) (<a id="P:88" class="idref" href="#P:88"><span class="id" title="binder">P</span></a> <a id="Q:89" class="idref" href="#Q:89"><span class="id" title="binder">Q</span></a> : <a class="idref" href="Logic.html#X:87"><span class="id" title="variable">X</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <span class="id" title="keyword">Prop</span>),<br/>
&nbsp;&nbsp;<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'&lt;-&gt;'_x"><span class="id" title="notation">(</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#a883bdd010993579f99d60b3775bcf54"><span class="id" title="notation">∃</span></a> <a id="x:90" class="idref" href="#x:90"><span class="id" title="binder">x</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#a883bdd010993579f99d60b3775bcf54"><span class="id" title="notation">,</span></a> <a class="idref" href="Logic.html#P:88"><span class="id" title="variable">P</span></a> <a class="idref" href="Logic.html#x:90"><span class="id" title="variable">x</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#f031fe1957c4a4a8e217aa46af2b4e<sub>25</sub>"><span class="id" title="notation">∨</span></a> <a class="idref" href="Logic.html#Q:89"><span class="id" title="variable">Q</span></a> <a class="idref" href="Logic.html#x:90"><span class="id" title="variable">x</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'&lt;-&gt;'_x"><span class="id" title="notation">)</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'&lt;-&gt;'_x"><span class="id" title="notation">↔</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#f031fe1957c4a4a8e217aa46af2b4e<sub>25</sub>"><span class="id" title="notation">(</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#a883bdd010993579f99d60b3775bcf54"><span class="id" title="notation">∃</span></a> <a id="x:91" class="idref" href="#x:91"><span class="id" title="binder">x</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#a883bdd010993579f99d60b3775bcf54"><span class="id" title="notation">,</span></a> <a class="idref" href="Logic.html#P:88"><span class="id" title="variable">P</span></a> <a class="idref" href="Logic.html#x:91"><span class="id" title="variable">x</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#f031fe1957c4a4a8e217aa46af2b4e<sub>25</sub>"><span class="id" title="notation">)</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#f031fe1957c4a4a8e217aa46af2b4e<sub>25</sub>"><span class="id" title="notation">∨</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#f031fe1957c4a4a8e217aa46af2b4e<sub>25</sub>"><span class="id" title="notation">(</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#a883bdd010993579f99d60b3775bcf54"><span class="id" title="notation">∃</span></a> <a id="x:92" class="idref" href="#x:92"><span class="id" title="binder">x</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#a883bdd010993579f99d60b3775bcf54"><span class="id" title="notation">,</span></a> <a class="idref" href="Logic.html#Q:89"><span class="id" title="variable">Q</span></a> <a class="idref" href="Logic.html#x:92"><span class="id" title="variable">x</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#f031fe1957c4a4a8e217aa46af2b4e<sub>25</sub>"><span class="id" title="notation">)</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;&nbsp;<span class="comment">(*&nbsp;FILL&nbsp;IN&nbsp;HERE&nbsp;*)</span> <span class="id" title="var">Admitted</span>.<br/>
<font size=-2>&#9744;</font>
</div>


<div class="doc">
<a id="lab189"></a><h1 class="section">Programming with Propositions</h1>

<div class="paragraph"> </div>

 The logical connectives that we have seen provide a rich
    vocabulary for defining complex propositions from simpler ones.
    To illustrate, let's look at how to express the claim that an
    element <span class="inlinecode"><span class="id" title="var">x</span></span> occurs in a list <span class="inlinecode"><span class="id" title="var">l</span></span>.  Notice that this property has a
    simple recursive structure: <ul class="doclist">
<li> If <span class="inlinecode"><span class="id" title="var">l</span></span> is the empty list, then <span class="inlinecode"><span class="id" title="var">x</span></span> cannot occur in it, so the
         property "<span class="inlinecode"><span class="id" title="var">x</span></span> appears in <span class="inlinecode"><span class="id" title="var">l</span></span>" is simply false. 
</li>
</ul>
<ul class="doclist">
<li> Otherwise, <span class="inlinecode"><span class="id" title="var">l</span></span> has the form <span class="inlinecode"><span class="id" title="var">x'</span></span> <span class="inlinecode">::</span> <span class="inlinecode"><span class="id" title="var">l'</span></span>.  In this case, <span class="inlinecode"><span class="id" title="var">x</span></span>
         occurs in <span class="inlinecode"><span class="id" title="var">l</span></span> if either it is equal to <span class="inlinecode"><span class="id" title="var">x'</span></span> or it occurs in
         <span class="inlinecode"><span class="id" title="var">l'</span></span>. 
</li>
</ul>

<div class="paragraph"> </div>

 We can translate this directly into a straightforward recursive
    function taking an element and a list and returning a proposition (!): 
</div>
<div class="code">

<span class="id" title="keyword">Fixpoint</span> <a id="In" class="idref" href="#In"><span class="id" title="definition">In</span></a> {<a id="A:93" class="idref" href="#A:93"><span class="id" title="binder">A</span></a> : <span class="id" title="keyword">Type</span>} (<a id="x:94" class="idref" href="#x:94"><span class="id" title="binder">x</span></a> : <a class="idref" href="Logic.html#A:93"><span class="id" title="variable">A</span></a>) (<a id="l:95" class="idref" href="#l:95"><span class="id" title="binder">l</span></a> : <a class="idref" href="Poly.html#list"><span class="id" title="inductive">list</span></a> <a class="idref" href="Logic.html#A:93"><span class="id" title="variable">A</span></a>) : <span class="id" title="keyword">Prop</span> :=<br/>
&nbsp;&nbsp;<span class="id" title="keyword">match</span> <a class="idref" href="Logic.html#l:95"><span class="id" title="variable">l</span></a> <span class="id" title="keyword">with</span><br/>
&nbsp;&nbsp;| <a class="idref" href="Poly.html#2c60282cbb04e070c60ae01e76f3865a"><span class="id" title="notation">[]</span></a> ⇒ <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#False"><span class="id" title="inductive">False</span></a><br/>
&nbsp;&nbsp;| <span class="id" title="var">x'</span> <a class="idref" href="Poly.html#:::x_'::'_x"><span class="id" title="notation">::</span></a> <span class="id" title="var">l'</span> ⇒ <span class="id" title="var">x'</span> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Logic.html#x:94"><span class="id" title="variable">x</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#f031fe1957c4a4a8e217aa46af2b4e<sub>25</sub>"><span class="id" title="notation">∨</span></a> <a class="idref" href="Logic.html#In:96"><span class="id" title="definition">In</span></a> <a class="idref" href="Logic.html#x:94"><span class="id" title="variable">x</span></a> <span class="id" title="var">l'</span><br/>
&nbsp;&nbsp;<span class="id" title="keyword">end</span>.<br/>
</div>

<div class="doc">
When <span class="inlinecode"><span class="id" title="var">In</span></span> is applied to a concrete list, it expands into a
    concrete sequence of nested disjunctions. 
</div>
<div class="code">

<span class="id" title="keyword">Example</span> <a id="In_example_1" class="idref" href="#In_example_1"><span class="id" title="definition">In_example_1</span></a> : <a class="idref" href="Logic.html#In"><span class="id" title="definition">In</span></a> 4 <a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">[</span></a>1<a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a> 2<a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a> 3<a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a> 4<a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a> 5<a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">]</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="comment">(*&nbsp;WORKED&nbsp;IN&nbsp;CLASS&nbsp;*)</span><br/>
&nbsp;&nbsp;<span class="id" title="tactic">simpl</span>. <span class="id" title="tactic">right</span>. <span class="id" title="tactic">right</span>. <span class="id" title="tactic">right</span>. <span class="id" title="tactic">left</span>. <span class="id" title="tactic">reflexivity</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Example</span> <a id="In_example_2" class="idref" href="#In_example_2"><span class="id" title="definition">In_example_2</span></a> :<br/>
&nbsp;&nbsp;<span class="id" title="keyword">∀</span> <a id="n:98" class="idref" href="#n:98"><span class="id" title="binder">n</span></a>, <a class="idref" href="Logic.html#In"><span class="id" title="definition">In</span></a> <a class="idref" href="Logic.html#n:98"><span class="id" title="variable">n</span></a> <a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">[</span></a>2<a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a> 4<a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">]</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a><br/>
&nbsp;&nbsp;<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#a883bdd010993579f99d60b3775bcf54"><span class="id" title="notation">∃</span></a> <a id="n':99" class="idref" href="#n':99"><span class="id" title="binder">n'</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#a883bdd010993579f99d60b3775bcf54"><span class="id" title="notation">,</span></a> <a class="idref" href="Logic.html#n:98"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> 2 <a class="idref" href="Basics.html#ea2ff3d561159081cea6fb2e8113cc<sub>54</sub>"><span class="id" title="notation">×</span></a> <a class="idref" href="Logic.html#n':99"><span class="id" title="variable">n'</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="comment">(*&nbsp;WORKED&nbsp;IN&nbsp;CLASS&nbsp;*)</span><br/>
&nbsp;&nbsp;<span class="id" title="tactic">simpl</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">intros</span> <span class="id" title="var">n</span> [<span class="id" title="var">H</span> | [<span class="id" title="var">H</span> | []]].<br/>
&nbsp;&nbsp;- <span class="id" title="tactic">∃</span> 1. <span class="id" title="tactic">rewrite</span> &lt;- <span class="id" title="var">H</span>. <span class="id" title="tactic">reflexivity</span>.<br/>
&nbsp;&nbsp;- <span class="id" title="tactic">∃</span> 2. <span class="id" title="tactic">rewrite</span> &lt;- <span class="id" title="var">H</span>. <span class="id" title="tactic">reflexivity</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>

<div class="doc">
(Notice the use of the empty pattern to discharge the last case
    <i>en passant</i>.) 
<div class="paragraph"> </div>

 We can also prove more generic, higher-level lemmas about <span class="inlinecode"><span class="id" title="var">In</span></span>.

<div class="paragraph"> </div>

    (Note how <span class="inlinecode"><span class="id" title="var">In</span></span> starts out applied to a variable and only gets
    expanded when we do case analysis on this variable.) 
</div>
<div class="code">

<span class="id" title="keyword">Theorem</span> <a id="In_map" class="idref" href="#In_map"><span class="id" title="lemma">In_map</span></a> :<br/>
&nbsp;&nbsp;<span class="id" title="keyword">∀</span> (<a id="A:100" class="idref" href="#A:100"><span class="id" title="binder">A</span></a> <a id="B:101" class="idref" href="#B:101"><span class="id" title="binder">B</span></a> : <span class="id" title="keyword">Type</span>) (<a id="f:102" class="idref" href="#f:102"><span class="id" title="binder">f</span></a> : <a class="idref" href="Logic.html#A:100"><span class="id" title="variable">A</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="Logic.html#B:101"><span class="id" title="variable">B</span></a>) (<a id="l:103" class="idref" href="#l:103"><span class="id" title="binder">l</span></a> : <a class="idref" href="Poly.html#list"><span class="id" title="inductive">list</span></a> <a class="idref" href="Logic.html#A:100"><span class="id" title="variable">A</span></a>) (<a id="x:104" class="idref" href="#x:104"><span class="id" title="binder">x</span></a> : <a class="idref" href="Logic.html#A:100"><span class="id" title="variable">A</span></a>),<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class="idref" href="Logic.html#In"><span class="id" title="definition">In</span></a> <a class="idref" href="Logic.html#x:104"><span class="id" title="variable">x</span></a> <a class="idref" href="Logic.html#l:103"><span class="id" title="variable">l</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a><br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class="idref" href="Logic.html#In"><span class="id" title="definition">In</span></a> (<a class="idref" href="Logic.html#f:102"><span class="id" title="variable">f</span></a> <a class="idref" href="Logic.html#x:104"><span class="id" title="variable">x</span></a>) (<a class="idref" href="Poly.html#map"><span class="id" title="definition">map</span></a> <a class="idref" href="Logic.html#f:102"><span class="id" title="variable">f</span></a> <a class="idref" href="Logic.html#l:103"><span class="id" title="variable">l</span></a>).<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">intros</span> <span class="id" title="var">A</span> <span class="id" title="var">B</span> <span class="id" title="var">f</span> <span class="id" title="var">l</span> <span class="id" title="var">x</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">induction</span> <span class="id" title="var">l</span> <span class="id" title="keyword">as</span> [|<span class="id" title="var">x'</span> <span class="id" title="var">l'</span> <span class="id" title="var">IHl'</span>].<br/>
&nbsp;&nbsp;- <span class="comment">(*&nbsp;l&nbsp;=&nbsp;nil,&nbsp;contradiction&nbsp;*)</span><br/>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="id" title="tactic">simpl</span>. <span class="id" title="tactic">intros</span> [].<br/>
&nbsp;&nbsp;- <span class="comment">(*&nbsp;l&nbsp;=&nbsp;x'&nbsp;::&nbsp;l'&nbsp;*)</span><br/>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="id" title="tactic">simpl</span>. <span class="id" title="tactic">intros</span> [<span class="id" title="var">H</span> | <span class="id" title="var">H</span>].<br/>
&nbsp;&nbsp;&nbsp;&nbsp;+ <span class="id" title="tactic">rewrite</span> <span class="id" title="var">H</span>. <span class="id" title="tactic">left</span>. <span class="id" title="tactic">reflexivity</span>.<br/>
&nbsp;&nbsp;&nbsp;&nbsp;+ <span class="id" title="tactic">right</span>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IHl'</span>. <span class="id" title="tactic">apply</span> <span class="id" title="var">H</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>

<div class="doc">
This way of defining propositions recursively, though convenient
    in some cases, also has some drawbacks.  In particular, it is
    subject to Coq's usual restrictions regarding the definition of
    recursive functions, e.g., the requirement that they be "obviously
    terminating."  In the next chapter, we will see how to define
    propositions <i>inductively</i>, a different technique with its own set
    of strengths and limitations. 
<div class="paragraph"> </div>

<a id="lab190"></a><h4 class="section">Exercise: 3 stars, standard (In_map_iff)</h4>

</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <a id="In_map_iff" class="idref" href="#In_map_iff"><span class="id" title="lemma">In_map_iff</span></a> :<br/>
&nbsp;&nbsp;<span class="id" title="keyword">∀</span> (<a id="A:105" class="idref" href="#A:105"><span class="id" title="binder">A</span></a> <a id="B:106" class="idref" href="#B:106"><span class="id" title="binder">B</span></a> : <span class="id" title="keyword">Type</span>) (<a id="f:107" class="idref" href="#f:107"><span class="id" title="binder">f</span></a> : <a class="idref" href="Logic.html#A:105"><span class="id" title="variable">A</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="Logic.html#B:106"><span class="id" title="variable">B</span></a>) (<a id="l:108" class="idref" href="#l:108"><span class="id" title="binder">l</span></a> : <a class="idref" href="Poly.html#list"><span class="id" title="inductive">list</span></a> <a class="idref" href="Logic.html#A:105"><span class="id" title="variable">A</span></a>) (<a id="y:109" class="idref" href="#y:109"><span class="id" title="binder">y</span></a> : <a class="idref" href="Logic.html#B:106"><span class="id" title="variable">B</span></a>),<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class="idref" href="Logic.html#In"><span class="id" title="definition">In</span></a> <a class="idref" href="Logic.html#y:109"><span class="id" title="variable">y</span></a> (<a class="idref" href="Poly.html#map"><span class="id" title="definition">map</span></a> <a class="idref" href="Logic.html#f:107"><span class="id" title="variable">f</span></a> <a class="idref" href="Logic.html#l:108"><span class="id" title="variable">l</span></a>) <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'&lt;-&gt;'_x"><span class="id" title="notation">↔</span></a><br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#a883bdd010993579f99d60b3775bcf54"><span class="id" title="notation">∃</span></a> <a id="x:110" class="idref" href="#x:110"><span class="id" title="binder">x</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#a883bdd010993579f99d60b3775bcf54"><span class="id" title="notation">,</span></a> <a class="idref" href="Logic.html#f:107"><span class="id" title="variable">f</span></a> <a class="idref" href="Logic.html#x:110"><span class="id" title="variable">x</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Logic.html#y:109"><span class="id" title="variable">y</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#ba2b0e492d2b4675a0acf3ea92aabadd"><span class="id" title="notation">∧</span></a> <a class="idref" href="Logic.html#In"><span class="id" title="definition">In</span></a> <a class="idref" href="Logic.html#x:110"><span class="id" title="variable">x</span></a> <a class="idref" href="Logic.html#l:108"><span class="id" title="variable">l</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">intros</span> <span class="id" title="var">A</span> <span class="id" title="var">B</span> <span class="id" title="var">f</span> <span class="id" title="var">l</span> <span class="id" title="var">y</span>. <span class="id" title="tactic">split</span>.<br/>
&nbsp;&nbsp;<span class="comment">(*&nbsp;FILL&nbsp;IN&nbsp;HERE&nbsp;*)</span> <span class="id" title="var">Admitted</span>.<br/>
<font size=-2>&#9744;</font>
</div>

<div class="doc"> 
<div class="paragraph"> </div>

<a id="lab191"></a><h4 class="section">Exercise: 2 stars, standard (In_app_iff)</h4>

</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <a id="In_app_iff" class="idref" href="#In_app_iff"><span class="id" title="lemma">In_app_iff</span></a> : <span class="id" title="keyword">∀</span> <a id="A:111" class="idref" href="#A:111"><span class="id" title="binder">A</span></a> <a id="l:112" class="idref" href="#l:112"><span class="id" title="binder">l</span></a> <a id="l':113" class="idref" href="#l':113"><span class="id" title="binder">l'</span></a> (<a id="a:114" class="idref" href="#a:114"><span class="id" title="binder">a</span></a>:<a class="idref" href="Logic.html#A:111"><span class="id" title="variable">A</span></a>),<br/>
&nbsp;&nbsp;<a class="idref" href="Logic.html#In"><span class="id" title="definition">In</span></a> <a class="idref" href="Logic.html#a:114"><span class="id" title="variable">a</span></a> (<a class="idref" href="Logic.html#l:112"><span class="id" title="variable">l</span></a><a class="idref" href="Poly.html#f03f7a04ef75ff3ac66ca5c23554e52e"><span class="id" title="notation">++</span></a><a class="idref" href="Logic.html#l':113"><span class="id" title="variable">l'</span></a>) <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'&lt;-&gt;'_x"><span class="id" title="notation">↔</span></a> <a class="idref" href="Logic.html#In"><span class="id" title="definition">In</span></a> <a class="idref" href="Logic.html#a:114"><span class="id" title="variable">a</span></a> <a class="idref" href="Logic.html#l:112"><span class="id" title="variable">l</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#f031fe1957c4a4a8e217aa46af2b4e<sub>25</sub>"><span class="id" title="notation">∨</span></a> <a class="idref" href="Logic.html#In"><span class="id" title="definition">In</span></a> <a class="idref" href="Logic.html#a:114"><span class="id" title="variable">a</span></a> <a class="idref" href="Logic.html#l':113"><span class="id" title="variable">l'</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">intros</span> <span class="id" title="var">A</span> <span class="id" title="var">l</span>. <span class="id" title="tactic">induction</span> <span class="id" title="var">l</span> <span class="id" title="keyword">as</span> [|<span class="id" title="var">a'</span> <span class="id" title="var">l'</span> <span class="id" title="var">IH</span>].<br/>
&nbsp;&nbsp;<span class="comment">(*&nbsp;FILL&nbsp;IN&nbsp;HERE&nbsp;*)</span> <span class="id" title="var">Admitted</span>.<br/>
<font size=-2>&#9744;</font>
</div>

<div class="doc"> 
<div class="paragraph"> </div>

<a id="lab192"></a><h4 class="section">Exercise: 3 stars, standard, especially useful (All)</h4>
 Recall that functions returning propositions can be seen as
    <i>properties</i> of their arguments. For instance, if <span class="inlinecode"><span class="id" title="var">P</span></span> has type
    <span class="inlinecode"><span class="id" title="var">nat</span></span> <span class="inlinecode">→</span> <span class="inlinecode"><span class="id" title="keyword">Prop</span></span>, then <span class="inlinecode"><span class="id" title="var">P</span></span> <span class="inlinecode"><span class="id" title="var">n</span></span> states that property <span class="inlinecode"><span class="id" title="var">P</span></span> holds of <span class="inlinecode"><span class="id" title="var">n</span></span>.

<div class="paragraph"> </div>

    Drawing inspiration from <span class="inlinecode"><span class="id" title="var">In</span></span>, write a recursive function <span class="inlinecode"><span class="id" title="keyword">All</span></span>
    stating that some property <span class="inlinecode"><span class="id" title="var">P</span></span> holds of all elements of a list
    <span class="inlinecode"><span class="id" title="var">l</span></span>. To make sure your definition is correct, prove the <span class="inlinecode"><span class="id" title="var">All_In</span></span>
    lemma below.  (Of course, your definition should <i>not</i> just
    restate the left-hand side of <span class="inlinecode"><span class="id" title="var">All_In</span></span>.) 
</div>
<div class="code">

<span class="id" title="keyword">Fixpoint</span> <a id="All" class="idref" href="#All"><span class="id" title="definition">All</span></a> {<a id="T:115" class="idref" href="#T:115"><span class="id" title="binder">T</span></a> : <span class="id" title="keyword">Type</span>} (<a id="P:116" class="idref" href="#P:116"><span class="id" title="binder">P</span></a> : <a class="idref" href="Logic.html#T:115"><span class="id" title="variable">T</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <span class="id" title="keyword">Prop</span>) (<a id="l:117" class="idref" href="#l:117"><span class="id" title="binder">l</span></a> : <a class="idref" href="Poly.html#list"><span class="id" title="inductive">list</span></a> <a class="idref" href="Logic.html#T:115"><span class="id" title="variable">T</span></a>) : <span class="id" title="keyword">Prop</span><br/>
&nbsp;&nbsp;<span class="comment">(*&nbsp;REPLACE&nbsp;THIS&nbsp;LINE&nbsp;WITH&nbsp;":=&nbsp;_your_definition_&nbsp;."&nbsp;*)</span>. <span class="id" title="var">Admitted</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Theorem</span> <a id="All_In" class="idref" href="#All_In"><span class="id" title="lemma">All_In</span></a> :<br/>
&nbsp;&nbsp;<span class="id" title="keyword">∀</span> <a id="T:119" class="idref" href="#T:119"><span class="id" title="binder">T</span></a> (<a id="P:120" class="idref" href="#P:120"><span class="id" title="binder">P</span></a> : <a class="idref" href="Logic.html#T:119"><span class="id" title="variable">T</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <span class="id" title="keyword">Prop</span>) (<a id="l:121" class="idref" href="#l:121"><span class="id" title="binder">l</span></a> : <a class="idref" href="Poly.html#list"><span class="id" title="inductive">list</span></a> <a class="idref" href="Logic.html#T:119"><span class="id" title="variable">T</span></a>),<br/>
&nbsp;&nbsp;&nbsp;&nbsp;<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'&lt;-&gt;'_x"><span class="id" title="notation">(</span></a><span class="id" title="keyword">∀</span> <a id="x:122" class="idref" href="#x:122"><span class="id" title="binder">x</span></a>, <a class="idref" href="Logic.html#In"><span class="id" title="definition">In</span></a> <a class="idref" href="Logic.html#x:122"><span class="id" title="variable">x</span></a> <a class="idref" href="Logic.html#l:121"><span class="id" title="variable">l</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="Logic.html#P:120"><span class="id" title="variable">P</span></a> <a class="idref" href="Logic.html#x:122"><span class="id" title="variable">x</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'&lt;-&gt;'_x"><span class="id" title="notation">)</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'&lt;-&gt;'_x"><span class="id" title="notation">↔</span></a><br/>
&nbsp;&nbsp;&nbsp;&nbsp;<a class="idref" href="Logic.html#All"><span class="id" title="axiom">All</span></a> <a class="idref" href="Logic.html#P:120"><span class="id" title="variable">P</span></a> <a class="idref" href="Logic.html#l:121"><span class="id" title="variable">l</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="comment">(*&nbsp;FILL&nbsp;IN&nbsp;HERE&nbsp;*)</span> <span class="id" title="var">Admitted</span>.<br/>
<font size=-2>&#9744;</font>
</div>

<div class="doc"> 
<div class="paragraph"> </div>

<a id="lab193"></a><h4 class="section">Exercise: 2 stars, standard, optional (combine_odd_even)</h4>
 Complete the definition of the <span class="inlinecode"><span class="id" title="var">combine_odd_even</span></span> function below.
    It takes as arguments two properties of numbers, <span class="inlinecode"><span class="id" title="var">Podd</span></span> and
    <span class="inlinecode"><span class="id" title="var">Peven</span></span>, and it should return a property <span class="inlinecode"><span class="id" title="var">P</span></span> such that <span class="inlinecode"><span class="id" title="var">P</span></span> <span class="inlinecode"><span class="id" title="var">n</span></span> is
    equivalent to <span class="inlinecode"><span class="id" title="var">Podd</span></span> <span class="inlinecode"><span class="id" title="var">n</span></span> when <span class="inlinecode"><span class="id" title="var">n</span></span> is odd and equivalent to <span class="inlinecode"><span class="id" title="var">Peven</span></span> <span class="inlinecode"><span class="id" title="var">n</span></span>
    otherwise. 
</div>
<div class="code">

<span class="id" title="keyword">Definition</span> <a id="combine_odd_even" class="idref" href="#combine_odd_even"><span class="id" title="definition">combine_odd_even</span></a> (<a id="Podd:123" class="idref" href="#Podd:123"><span class="id" title="binder">Podd</span></a> <a id="Peven:124" class="idref" href="#Peven:124"><span class="id" title="binder">Peven</span></a> : <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#nat"><span class="id" title="inductive">nat</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <span class="id" title="keyword">Prop</span>) : <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#nat"><span class="id" title="inductive">nat</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <span class="id" title="keyword">Prop</span><br/>
&nbsp;&nbsp;<span class="comment">(*&nbsp;REPLACE&nbsp;THIS&nbsp;LINE&nbsp;WITH&nbsp;":=&nbsp;_your_definition_&nbsp;."&nbsp;*)</span>. <span class="id" title="var">Admitted</span>.<br/>
</div>

<div class="doc">
To test your definition, prove the following facts: 
</div>
<div class="code">

<span class="id" title="keyword">Theorem</span> <a id="combine_odd_even_intro" class="idref" href="#combine_odd_even_intro"><span class="id" title="lemma">combine_odd_even_intro</span></a> :<br/>
&nbsp;&nbsp;<span class="id" title="keyword">∀</span> (<a id="Podd:125" class="idref" href="#Podd:125"><span class="id" title="binder">Podd</span></a> <a id="Peven:126" class="idref" href="#Peven:126"><span class="id" title="binder">Peven</span></a> : <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#nat"><span class="id" title="inductive">nat</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <span class="id" title="keyword">Prop</span>) (<a id="n:127" class="idref" href="#n:127"><span class="id" title="binder">n</span></a> : <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#nat"><span class="id" title="inductive">nat</span></a>),<br/>
&nbsp;&nbsp;&nbsp;&nbsp;<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">(</span></a><a class="idref" href="Basics.html#odd"><span class="id" title="definition">odd</span></a> <a class="idref" href="Logic.html#n:127"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Basics.html#true"><span class="id" title="constructor">true</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="Logic.html#Podd:125"><span class="id" title="variable">Podd</span></a> <a class="idref" href="Logic.html#n:127"><span class="id" title="variable">n</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">)</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a><br/>
&nbsp;&nbsp;&nbsp;&nbsp;<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">(</span></a><a class="idref" href="Basics.html#odd"><span class="id" title="definition">odd</span></a> <a class="idref" href="Logic.html#n:127"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Basics.html#false"><span class="id" title="constructor">false</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="Logic.html#Peven:126"><span class="id" title="variable">Peven</span></a> <a class="idref" href="Logic.html#n:127"><span class="id" title="variable">n</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">)</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a><br/>
&nbsp;&nbsp;&nbsp;&nbsp;<a class="idref" href="Logic.html#combine_odd_even"><span class="id" title="axiom">combine_odd_even</span></a> <a class="idref" href="Logic.html#Podd:125"><span class="id" title="variable">Podd</span></a> <a class="idref" href="Logic.html#Peven:126"><span class="id" title="variable">Peven</span></a> <a class="idref" href="Logic.html#n:127"><span class="id" title="variable">n</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="comment">(*&nbsp;FILL&nbsp;IN&nbsp;HERE&nbsp;*)</span> <span class="id" title="var">Admitted</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Theorem</span> <a id="combine_odd_even_elim_odd" class="idref" href="#combine_odd_even_elim_odd"><span class="id" title="lemma">combine_odd_even_elim_odd</span></a> :<br/>
&nbsp;&nbsp;<span class="id" title="keyword">∀</span> (<a id="Podd:128" class="idref" href="#Podd:128"><span class="id" title="binder">Podd</span></a> <a id="Peven:129" class="idref" href="#Peven:129"><span class="id" title="binder">Peven</span></a> : <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#nat"><span class="id" title="inductive">nat</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <span class="id" title="keyword">Prop</span>) (<a id="n:130" class="idref" href="#n:130"><span class="id" title="binder">n</span></a> : <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#nat"><span class="id" title="inductive">nat</span></a>),<br/>
&nbsp;&nbsp;&nbsp;&nbsp;<a class="idref" href="Logic.html#combine_odd_even"><span class="id" title="axiom">combine_odd_even</span></a> <a class="idref" href="Logic.html#Podd:128"><span class="id" title="variable">Podd</span></a> <a class="idref" href="Logic.html#Peven:129"><span class="id" title="variable">Peven</span></a> <a class="idref" href="Logic.html#n:130"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a><br/>
&nbsp;&nbsp;&nbsp;&nbsp;<a class="idref" href="Basics.html#odd"><span class="id" title="definition">odd</span></a> <a class="idref" href="Logic.html#n:130"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Basics.html#true"><span class="id" title="constructor">true</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a><br/>
&nbsp;&nbsp;&nbsp;&nbsp;<a class="idref" href="Logic.html#Podd:128"><span class="id" title="variable">Podd</span></a> <a class="idref" href="Logic.html#n:130"><span class="id" title="variable">n</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="comment">(*&nbsp;FILL&nbsp;IN&nbsp;HERE&nbsp;*)</span> <span class="id" title="var">Admitted</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Theorem</span> <a id="combine_odd_even_elim_even" class="idref" href="#combine_odd_even_elim_even"><span class="id" title="lemma">combine_odd_even_elim_even</span></a> :<br/>
&nbsp;&nbsp;<span class="id" title="keyword">∀</span> (<a id="Podd:131" class="idref" href="#Podd:131"><span class="id" title="binder">Podd</span></a> <a id="Peven:132" class="idref" href="#Peven:132"><span class="id" title="binder">Peven</span></a> : <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#nat"><span class="id" title="inductive">nat</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <span class="id" title="keyword">Prop</span>) (<a id="n:133" class="idref" href="#n:133"><span class="id" title="binder">n</span></a> : <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#nat"><span class="id" title="inductive">nat</span></a>),<br/>
&nbsp;&nbsp;&nbsp;&nbsp;<a class="idref" href="Logic.html#combine_odd_even"><span class="id" title="axiom">combine_odd_even</span></a> <a class="idref" href="Logic.html#Podd:131"><span class="id" title="variable">Podd</span></a> <a class="idref" href="Logic.html#Peven:132"><span class="id" title="variable">Peven</span></a> <a class="idref" href="Logic.html#n:133"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a><br/>
&nbsp;&nbsp;&nbsp;&nbsp;<a class="idref" href="Basics.html#odd"><span class="id" title="definition">odd</span></a> <a class="idref" href="Logic.html#n:133"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Basics.html#false"><span class="id" title="constructor">false</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a><br/>
&nbsp;&nbsp;&nbsp;&nbsp;<a class="idref" href="Logic.html#Peven:132"><span class="id" title="variable">Peven</span></a> <a class="idref" href="Logic.html#n:133"><span class="id" title="variable">n</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="comment">(*&nbsp;FILL&nbsp;IN&nbsp;HERE&nbsp;*)</span> <span class="id" title="var">Admitted</span>.<br/>
<font size=-2>&#9744;</font>
</div>


<div class="doc">
<a id="lab194"></a><h1 class="section">Applying Theorems to Arguments</h1>

<div class="paragraph"> </div>

 One feature that distinguishes Coq from some other popular
    proof assistants (e.g., ACL2 and Isabelle) is that it treats
    <i>proofs</i> as first-class objects.

<div class="paragraph"> </div>

    There is a great deal to be said about this, but it is not
    necessary to understand it all in detail in order to use Coq.
    This section gives just a taste, while a deeper exploration can be
    found in the optional chapters <span class="inlinecode"><span class="id" title="var">ProofObjects</span></span> and
    <span class="inlinecode"><span class="id" title="var">IndPrinciples</span></span>. 
<div class="paragraph"> </div>

 We have seen that we can use <span class="inlinecode"><span class="id" title="keyword">Check</span></span> to ask Coq to print the type
    of an expression.  We can also use it to ask what theorem a
    particular identifier refers to. 
</div>
<div class="code">

<span class="id" title="keyword">Check</span> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Peano.html#plus"><span class="id" title="abbreviation">plus</span></a>      : <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#nat"><span class="id" title="inductive">nat</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#nat"><span class="id" title="inductive">nat</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#nat"><span class="id" title="inductive">nat</span></a>.<br/>
<span class="id" title="keyword">Check</span> <a class="idref" href="Induction.html#add_comm"><span class="id" title="axiom">add_comm</span></a> : <span class="id" title="keyword">∀</span> <a id="n:134" class="idref" href="#n:134"><span class="id" title="binder">n</span></a> <a id="m:135" class="idref" href="#m:135"><span class="id" title="binder">m</span></a> : <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#nat"><span class="id" title="inductive">nat</span></a>, <a class="idref" href="Logic.html#n:134"><span class="id" title="variable">n</span></a> <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> <a class="idref" href="Logic.html#m:135"><span class="id" title="variable">m</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Logic.html#m:135"><span class="id" title="variable">m</span></a> <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> <a class="idref" href="Logic.html#n:134"><span class="id" title="variable">n</span></a>.<br/>
</div>

<div class="doc">
Coq checks the <i>statement</i> of the <span class="inlinecode"><span class="id" title="var">add_comm</span></span> theorem (or prints
    it for us, if we leave off the part beginning with the colon) in
    the same way that it checks the <i>type</i> of any term (e.g., plus)
    that we ask it to <span class="inlinecode"><span class="id" title="keyword">Check</span></span>. Why? 
<div class="paragraph"> </div>

 The reason is that the identifier <span class="inlinecode"><span class="id" title="var">add_comm</span></span> actually refers to a
    <i>proof object</i>, which represents a logical derivation establishing
    of the truth of the statement <span class="inlinecode"><span class="id" title="keyword">∀</span></span> <span class="inlinecode"><span class="id" title="var">n</span></span> <span class="inlinecode"><span class="id" title="var">m</span></span> <span class="inlinecode">:</span> <span class="inlinecode"><span class="id" title="var">nat</span>,</span> <span class="inlinecode"><span class="id" title="var">n</span></span> <span class="inlinecode">+</span> <span class="inlinecode"><span class="id" title="var">m</span></span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" title="var">m</span></span> <span class="inlinecode">+</span> <span class="inlinecode"><span class="id" title="var">n</span></span>.  The
    type of this object is the proposition which it is a proof of. 
<div class="paragraph"> </div>

 Intuitively, this makes sense because the statement of a
    theorem tells us what we can use that theorem for. 
<div class="paragraph"> </div>

 Operationally, this analogy goes even further: by applying a
    theorem as if it were a function, i.e., applying it to values and
    hypotheses with matching types, we can specialize its result
    without having to resort to intermediate assertions.  For example,
    suppose we wanted to prove the following result: 
</div>
<div class="code">

<span class="id" title="keyword">Lemma</span> <a id="add_comm3" class="idref" href="#add_comm3"><span class="id" title="lemma">add_comm3</span></a> :<br/>
&nbsp;&nbsp;<span class="id" title="keyword">∀</span> <a id="x:136" class="idref" href="#x:136"><span class="id" title="binder">x</span></a> <a id="y:137" class="idref" href="#y:137"><span class="id" title="binder">y</span></a> <a id="z:138" class="idref" href="#z:138"><span class="id" title="binder">z</span></a>, <a class="idref" href="Logic.html#x:136"><span class="id" title="variable">x</span></a> <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">(</span></a><a class="idref" href="Logic.html#y:137"><span class="id" title="variable">y</span></a> <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> <a class="idref" href="Logic.html#z:138"><span class="id" title="variable">z</span></a><a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">)</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">(</span></a><a class="idref" href="Logic.html#z:138"><span class="id" title="variable">z</span></a> <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> <a class="idref" href="Logic.html#y:137"><span class="id" title="variable">y</span></a><a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">)</span></a> <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> <a class="idref" href="Logic.html#x:136"><span class="id" title="variable">x</span></a>.<br/>
</div>

<div class="doc">
It appears at first sight that we ought to be able to prove this
    by rewriting with <span class="inlinecode"><span class="id" title="var">add_comm</span></span> twice to make the two sides match.
    The problem, however, is that the second <span class="inlinecode"><span class="id" title="tactic">rewrite</span></span> will undo the
    effect of the first. 
</div>
<div class="code">

<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="comment">(*&nbsp;WORKED&nbsp;IN&nbsp;CLASS&nbsp;*)</span><br/>
&nbsp;&nbsp;<span class="id" title="tactic">intros</span> <span class="id" title="var">x</span> <span class="id" title="var">y</span> <span class="id" title="var">z</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">rewrite</span> <a class="idref" href="Induction.html#add_comm"><span class="id" title="axiom">add_comm</span></a>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">rewrite</span> <a class="idref" href="Induction.html#add_comm"><span class="id" title="axiom">add_comm</span></a>.<br/>
&nbsp;&nbsp;<span class="comment">(*&nbsp;We&nbsp;are&nbsp;back&nbsp;where&nbsp;we&nbsp;started...&nbsp;*)</span><br/>
<span class="id" title="keyword">Abort</span>.<br/>
</div>

<div class="doc">
We saw similar problems back in Chapter <span class="inlinecode"><span class="id" title="keyword">Induction</span></span>, and saw one
    way to work around them by using <span class="inlinecode"><span class="id" title="tactic">assert</span></span> to derive a specialized
    version of <span class="inlinecode"><span class="id" title="var">add_comm</span></span> that can be used to rewrite exactly where
    we want. 
</div>
<div class="code">

<span class="id" title="keyword">Lemma</span> <a id="add_comm3_take2" class="idref" href="#add_comm3_take2"><span class="id" title="lemma">add_comm3_take2</span></a> :<br/>
&nbsp;&nbsp;<span class="id" title="keyword">∀</span> <a id="x:139" class="idref" href="#x:139"><span class="id" title="binder">x</span></a> <a id="y:140" class="idref" href="#y:140"><span class="id" title="binder">y</span></a> <a id="z:141" class="idref" href="#z:141"><span class="id" title="binder">z</span></a>, <a class="idref" href="Logic.html#x:139"><span class="id" title="variable">x</span></a> <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">(</span></a><a class="idref" href="Logic.html#y:140"><span class="id" title="variable">y</span></a> <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> <a class="idref" href="Logic.html#z:141"><span class="id" title="variable">z</span></a><a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">)</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">(</span></a><a class="idref" href="Logic.html#z:141"><span class="id" title="variable">z</span></a> <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> <a class="idref" href="Logic.html#y:140"><span class="id" title="variable">y</span></a><a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">)</span></a> <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> <a class="idref" href="Logic.html#x:139"><span class="id" title="variable">x</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">intros</span> <span class="id" title="var">x</span> <span class="id" title="var">y</span> <span class="id" title="var">z</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">rewrite</span> <a class="idref" href="Induction.html#add_comm"><span class="id" title="axiom">add_comm</span></a>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">assert</span> (<span class="id" title="var">H</span> : <span class="id" title="var">y</span> <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> <span class="id" title="var">z</span> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <span class="id" title="var">z</span> <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> <span class="id" title="var">y</span>).<br/>
&nbsp;&nbsp;{ <span class="id" title="tactic">rewrite</span> <a class="idref" href="Induction.html#add_comm"><span class="id" title="axiom">add_comm</span></a>. <span class="id" title="tactic">reflexivity</span>. }<br/>
&nbsp;&nbsp;<span class="id" title="tactic">rewrite</span> <span class="id" title="var">H</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">reflexivity</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>

<div class="doc">
A more elegant alternative is to apply <span class="inlinecode"><span class="id" title="var">add_comm</span></span> directly
    to the arguments we want to instantiate it with, in much the same
    way as we apply a polymorphic function to a type argument. 
</div>
<div class="code">

<span class="id" title="keyword">Lemma</span> <a id="add_comm3_take3" class="idref" href="#add_comm3_take3"><span class="id" title="lemma">add_comm3_take3</span></a> :<br/>
&nbsp;&nbsp;<span class="id" title="keyword">∀</span> <a id="x:142" class="idref" href="#x:142"><span class="id" title="binder">x</span></a> <a id="y:143" class="idref" href="#y:143"><span class="id" title="binder">y</span></a> <a id="z:144" class="idref" href="#z:144"><span class="id" title="binder">z</span></a>, <a class="idref" href="Logic.html#x:142"><span class="id" title="variable">x</span></a> <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">(</span></a><a class="idref" href="Logic.html#y:143"><span class="id" title="variable">y</span></a> <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> <a class="idref" href="Logic.html#z:144"><span class="id" title="variable">z</span></a><a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">)</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">(</span></a><a class="idref" href="Logic.html#z:144"><span class="id" title="variable">z</span></a> <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> <a class="idref" href="Logic.html#y:143"><span class="id" title="variable">y</span></a><a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">)</span></a> <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> <a class="idref" href="Logic.html#x:142"><span class="id" title="variable">x</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">intros</span> <span class="id" title="var">x</span> <span class="id" title="var">y</span> <span class="id" title="var">z</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">rewrite</span> <a class="idref" href="Induction.html#add_comm"><span class="id" title="axiom">add_comm</span></a>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">rewrite</span> (<a class="idref" href="Induction.html#add_comm"><span class="id" title="axiom">add_comm</span></a> <span class="id" title="var">y</span> <span class="id" title="var">z</span>).<br/>
&nbsp;&nbsp;<span class="id" title="tactic">reflexivity</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>

<div class="doc">
Let's see another example of using a theorem like a function. 

<div class="paragraph"> </div>

    The following theorem says: any list <span class="inlinecode"><span class="id" title="var">l</span></span> containing some element
    must be nonempty. 
</div>
<div class="code">

<span class="id" title="keyword">Theorem</span> <a id="in_not_nil" class="idref" href="#in_not_nil"><span class="id" title="lemma">in_not_nil</span></a> :<br/>
&nbsp;&nbsp;<span class="id" title="keyword">∀</span> <a id="A:145" class="idref" href="#A:145"><span class="id" title="binder">A</span></a> (<a id="x:146" class="idref" href="#x:146"><span class="id" title="binder">x</span></a> : <a class="idref" href="Logic.html#A:145"><span class="id" title="variable">A</span></a>) (<a id="l:147" class="idref" href="#l:147"><span class="id" title="binder">l</span></a> : <a class="idref" href="Poly.html#list"><span class="id" title="inductive">list</span></a> <a class="idref" href="Logic.html#A:145"><span class="id" title="variable">A</span></a>), <a class="idref" href="Logic.html#In"><span class="id" title="definition">In</span></a> <a class="idref" href="Logic.html#x:146"><span class="id" title="variable">x</span></a> <a class="idref" href="Logic.html#l:147"><span class="id" title="variable">l</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="Logic.html#l:147"><span class="id" title="variable">l</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'&lt;&gt;'_x"><span class="id" title="notation">≠</span></a> <a class="idref" href="Poly.html#2c60282cbb04e070c60ae01e76f3865a"><span class="id" title="notation">[]</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">intros</span> <span class="id" title="var">A</span> <span class="id" title="var">x</span> <span class="id" title="var">l</span> <span class="id" title="var">H</span>. <span class="id" title="tactic">unfold</span> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#not"><span class="id" title="definition">not</span></a>. <span class="id" title="tactic">intro</span> <span class="id" title="var">Hl</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">rewrite</span> <span class="id" title="var">Hl</span> <span class="id" title="keyword">in</span> <span class="id" title="var">H</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">simpl</span> <span class="id" title="keyword">in</span> <span class="id" title="var">H</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">apply</span> <span class="id" title="var">H</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>

<div class="doc">
What makes this interesting is that one quantified variable
    (<span class="inlinecode"><span class="id" title="var">x</span></span>) does not appear in the conclusion (<span class="inlinecode"><span class="id" title="var">l</span></span> <span class="inlinecode">≠</span> <span class="inlinecode">[]</span>). 
<div class="paragraph"> </div>

 We should be able to use this theorem to prove the special case
    where <span class="inlinecode"><span class="id" title="var">x</span></span> is <span class="inlinecode">42</span>. However, naively, the tactic <span class="inlinecode"><span class="id" title="tactic">apply</span></span> <span class="inlinecode"><span class="id" title="var">in_not_nil</span></span>
    will fail because it cannot infer the value of <span class="inlinecode"><span class="id" title="var">x</span></span>. 
</div>
<div class="code">

<span class="id" title="keyword">Lemma</span> <a id="in_not_nil_42" class="idref" href="#in_not_nil_42"><span class="id" title="lemma">in_not_nil_42</span></a> :<br/>
&nbsp;&nbsp;<span class="id" title="keyword">∀</span> <a id="l:148" class="idref" href="#l:148"><span class="id" title="binder">l</span></a> : <a class="idref" href="Poly.html#list"><span class="id" title="inductive">list</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#nat"><span class="id" title="inductive">nat</span></a>, <a class="idref" href="Logic.html#In"><span class="id" title="definition">In</span></a> 42 <a class="idref" href="Logic.html#l:148"><span class="id" title="variable">l</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="Logic.html#l:148"><span class="id" title="variable">l</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'&lt;&gt;'_x"><span class="id" title="notation">≠</span></a> <a class="idref" href="Poly.html#2c60282cbb04e070c60ae01e76f3865a"><span class="id" title="notation">[]</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">intros</span> <span class="id" title="var">l</span> <span class="id" title="var">H</span>.<br/>
&nbsp;&nbsp;<span class="id" title="var">Fail</span> <span class="id" title="tactic">apply</span> <a class="idref" href="Logic.html#in_not_nil"><span class="id" title="lemma">in_not_nil</span></a>.<br/>
<span class="id" title="keyword">Abort</span>.<br/>
</div>

<div class="doc">
There are several ways to work around this: 
<div class="paragraph"> </div>

 Use <span class="inlinecode"><span class="id" title="tactic">apply</span></span> <span class="inlinecode">...</span> <span class="inlinecode"><span class="id" title="keyword">with</span></span> <span class="inlinecode">...</span> 
</div>
<div class="code">
<span class="id" title="keyword">Lemma</span> <a id="in_not_nil_42_take2" class="idref" href="#in_not_nil_42_take2"><span class="id" title="lemma">in_not_nil_42_take2</span></a> :<br/>
&nbsp;&nbsp;<span class="id" title="keyword">∀</span> <a id="l:149" class="idref" href="#l:149"><span class="id" title="binder">l</span></a> : <a class="idref" href="Poly.html#list"><span class="id" title="inductive">list</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#nat"><span class="id" title="inductive">nat</span></a>, <a class="idref" href="Logic.html#In"><span class="id" title="definition">In</span></a> 42 <a class="idref" href="Logic.html#l:149"><span class="id" title="variable">l</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="Logic.html#l:149"><span class="id" title="variable">l</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'&lt;&gt;'_x"><span class="id" title="notation">≠</span></a> <a class="idref" href="Poly.html#2c60282cbb04e070c60ae01e76f3865a"><span class="id" title="notation">[]</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">intros</span> <span class="id" title="var">l</span> <span class="id" title="var">H</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">apply</span> <a class="idref" href="Logic.html#in_not_nil"><span class="id" title="lemma">in_not_nil</span></a> <span class="id" title="keyword">with</span> (<span class="id" title="var">x</span> := 42).<br/>
&nbsp;&nbsp;<span class="id" title="tactic">apply</span> <span class="id" title="var">H</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>

<div class="doc">
Use <span class="inlinecode"><span class="id" title="tactic">apply</span></span> <span class="inlinecode">...</span> <span class="inlinecode"><span class="id" title="keyword">in</span></span> <span class="inlinecode">...</span> 
</div>
<div class="code">
<span class="id" title="keyword">Lemma</span> <a id="in_not_nil_42_take3" class="idref" href="#in_not_nil_42_take3"><span class="id" title="lemma">in_not_nil_42_take3</span></a> :<br/>
&nbsp;&nbsp;<span class="id" title="keyword">∀</span> <a id="l:150" class="idref" href="#l:150"><span class="id" title="binder">l</span></a> : <a class="idref" href="Poly.html#list"><span class="id" title="inductive">list</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#nat"><span class="id" title="inductive">nat</span></a>, <a class="idref" href="Logic.html#In"><span class="id" title="definition">In</span></a> 42 <a class="idref" href="Logic.html#l:150"><span class="id" title="variable">l</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="Logic.html#l:150"><span class="id" title="variable">l</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'&lt;&gt;'_x"><span class="id" title="notation">≠</span></a> <a class="idref" href="Poly.html#2c60282cbb04e070c60ae01e76f3865a"><span class="id" title="notation">[]</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">intros</span> <span class="id" title="var">l</span> <span class="id" title="var">H</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">apply</span> <a class="idref" href="Logic.html#in_not_nil"><span class="id" title="lemma">in_not_nil</span></a> <span class="id" title="keyword">in</span> <span class="id" title="var">H</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">apply</span> <span class="id" title="var">H</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>

<div class="doc">
Explicitly apply the lemma to the value for <span class="inlinecode"><span class="id" title="var">x</span></span>. 
</div>
<div class="code">
<span class="id" title="keyword">Lemma</span> <a id="in_not_nil_42_take4" class="idref" href="#in_not_nil_42_take4"><span class="id" title="lemma">in_not_nil_42_take4</span></a> :<br/>
&nbsp;&nbsp;<span class="id" title="keyword">∀</span> <a id="l:151" class="idref" href="#l:151"><span class="id" title="binder">l</span></a> : <a class="idref" href="Poly.html#list"><span class="id" title="inductive">list</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#nat"><span class="id" title="inductive">nat</span></a>, <a class="idref" href="Logic.html#In"><span class="id" title="definition">In</span></a> 42 <a class="idref" href="Logic.html#l:151"><span class="id" title="variable">l</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="Logic.html#l:151"><span class="id" title="variable">l</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'&lt;&gt;'_x"><span class="id" title="notation">≠</span></a> <a class="idref" href="Poly.html#2c60282cbb04e070c60ae01e76f3865a"><span class="id" title="notation">[]</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">intros</span> <span class="id" title="var">l</span> <span class="id" title="var">H</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">apply</span> (<a class="idref" href="Logic.html#in_not_nil"><span class="id" title="lemma">in_not_nil</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#nat"><span class="id" title="inductive">nat</span></a> 42).<br/>
&nbsp;&nbsp;<span class="id" title="tactic">apply</span> <span class="id" title="var">H</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>

<div class="doc">
Explicitly apply the lemma to a hypothesis. 
</div>
<div class="code">
<span class="id" title="keyword">Lemma</span> <a id="in_not_nil_42_take5" class="idref" href="#in_not_nil_42_take5"><span class="id" title="lemma">in_not_nil_42_take5</span></a> :<br/>
&nbsp;&nbsp;<span class="id" title="keyword">∀</span> <a id="l:152" class="idref" href="#l:152"><span class="id" title="binder">l</span></a> : <a class="idref" href="Poly.html#list"><span class="id" title="inductive">list</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#nat"><span class="id" title="inductive">nat</span></a>, <a class="idref" href="Logic.html#In"><span class="id" title="definition">In</span></a> 42 <a class="idref" href="Logic.html#l:152"><span class="id" title="variable">l</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="Logic.html#l:152"><span class="id" title="variable">l</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'&lt;&gt;'_x"><span class="id" title="notation">≠</span></a> <a class="idref" href="Poly.html#2c60282cbb04e070c60ae01e76f3865a"><span class="id" title="notation">[]</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">intros</span> <span class="id" title="var">l</span> <span class="id" title="var">H</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">apply</span> (<a class="idref" href="Logic.html#in_not_nil"><span class="id" title="lemma">in_not_nil</span></a> <span class="id" title="var">_</span> <span class="id" title="var">_</span> <span class="id" title="var">_</span> <span class="id" title="var">H</span>).<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>

<div class="doc">
You can "use theorems as functions" in this way with almost all
    tactics that take a theorem name as an argument.  Note also that
    theorem application uses the same inference mechanisms as function
    application; thus, it is possible, for example, to supply
    wildcards as arguments to be inferred, or to declare some
    hypotheses to a theorem as implicit by default.  These features
    are illustrated in the proof below. (The details of how this proof
    works are not critical -- the goal here is just to illustrate what
    can be done.) 
</div>
<div class="code">

<span class="id" title="keyword">Example</span> <a id="lemma_application_ex" class="idref" href="#lemma_application_ex"><span class="id" title="definition">lemma_application_ex</span></a> :<br/>
&nbsp;&nbsp;<span class="id" title="keyword">∀</span> {<a id="n:153" class="idref" href="#n:153"><span class="id" title="binder">n</span></a> : <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#nat"><span class="id" title="inductive">nat</span></a>} {<a id="ns:154" class="idref" href="#ns:154"><span class="id" title="binder">ns</span></a> : <a class="idref" href="Poly.html#list"><span class="id" title="inductive">list</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#nat"><span class="id" title="inductive">nat</span></a>},<br/>
&nbsp;&nbsp;&nbsp;&nbsp;<a class="idref" href="Logic.html#In"><span class="id" title="definition">In</span></a> <a class="idref" href="Logic.html#n:153"><span class="id" title="variable">n</span></a> (<a class="idref" href="Poly.html#map"><span class="id" title="definition">map</span></a> (<span class="id" title="keyword">fun</span> <a id="m:155" class="idref" href="#m:155"><span class="id" title="binder">m</span></a> ⇒ <a class="idref" href="Logic.html#m:155"><span class="id" title="variable">m</span></a> <a class="idref" href="Basics.html#ea2ff3d561159081cea6fb2e8113cc<sub>54</sub>"><span class="id" title="notation">×</span></a> 0) <a class="idref" href="Logic.html#ns:154"><span class="id" title="variable">ns</span></a>) <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a><br/>
&nbsp;&nbsp;&nbsp;&nbsp;<a class="idref" href="Logic.html#n:153"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> 0.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">intros</span> <span class="id" title="var">n</span> <span class="id" title="var">ns</span> <span class="id" title="var">H</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">destruct</span> (<a class="idref" href="Logic.html#proj1"><span class="id" title="lemma">proj1</span></a> <span class="id" title="var">_</span> <span class="id" title="var">_</span> (<a class="idref" href="Logic.html#In_map_iff"><span class="id" title="axiom">In_map_iff</span></a> <span class="id" title="var">_</span> <span class="id" title="var">_</span> <span class="id" title="var">_</span> <span class="id" title="var">_</span> <span class="id" title="var">_</span>) <span class="id" title="var">H</span>)<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="id" title="keyword">as</span> [<span class="id" title="var">m</span> [<span class="id" title="var">Hm</span> <span class="id" title="var">_</span>]].<br/>
&nbsp;&nbsp;<span class="id" title="tactic">rewrite</span> <a class="idref" href="Induction.html#mul_0_r"><span class="id" title="axiom">mul_0_r</span></a> <span class="id" title="keyword">in</span> <span class="id" title="var">Hm</span>. <span class="id" title="tactic">rewrite</span> &lt;- <span class="id" title="var">Hm</span>. <span class="id" title="tactic">reflexivity</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>

<div class="doc">
We will see many more examples in later chapters. 
</div>

<div class="doc">
<a id="lab195"></a><h1 class="section">Coq vs. Set Theory</h1>

<div class="paragraph"> </div>

 Coq's logical core, the <i>Calculus of Inductive
    Constructions</i>, differs in some important ways from other formal
    systems that are used by mathematicians to write down precise and
    rigorous definitions and proofs.  For example, in the most popular
    foundation for paper-and-pencil mathematics, Zermelo-Fraenkel Set
    Theory (ZFC), a mathematical object can potentially be a member of
    many different sets; a term in Coq's logic, on the other hand, is
    a member of at most one type.  This difference often leads to
    slightly different ways of capturing informal mathematical
    concepts, but these are, by and large, about equally natural and
    easy to work with.  For example, instead of saying that a natural
    number <span class="inlinecode"><span class="id" title="var">n</span></span> belongs to the set of even numbers, we would say in Coq
    that <span class="inlinecode"><span class="id" title="var">Even</span></span> <span class="inlinecode"><span class="id" title="var">n</span></span> holds, where <span class="inlinecode"><span class="id" title="var">Even</span></span> <span class="inlinecode">:</span> <span class="inlinecode"><span class="id" title="var">nat</span></span> <span class="inlinecode">→</span> <span class="inlinecode"><span class="id" title="keyword">Prop</span></span> is a property
    describing even numbers.

<div class="paragraph"> </div>

    We conclude this chapter with a brief discussion of some of the
    most significant differences between the two worlds. 
<div class="paragraph"> </div>

<a id="lab196"></a><h2 class="section">Functional Extensionality</h2>

<div class="paragraph"> </div>

 Coq's logic is intentionally quite minimal.  This means that there
    are occasionally some cases where translating standard
    mathematical reasoning into Coq can be cumbersome or sometimes
    even impossible, unless we enrich the core logic with additional
    axioms. 
<div class="paragraph"> </div>

 The equality assertions that we have seen so far mostly have
    concerned elements of inductive types (<span class="inlinecode"><span class="id" title="var">nat</span></span>, <span class="inlinecode"><span class="id" title="var">bool</span></span>, etc.).  But,
    since Coq's equality operator is polymorphic, we can use it at
    <i>any</i> type -- in particular, we can write propositions claiming
    that two <i>functions</i> are equal to each other: 
</div>
<div class="code">

<span class="id" title="keyword">Example</span> <a id="function_equality_ex<sub>1</sub>" class="idref" href="#function_equality_ex<sub>1</sub>"><span class="id" title="definition">function_equality_ex<sub>1</sub></span></a> :<br/>
&nbsp;&nbsp;<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">(</span></a><span class="id" title="keyword">fun</span> <a id="x:156" class="idref" href="#x:156"><span class="id" title="binder">x</span></a> ⇒ 3 <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> <a class="idref" href="Logic.html#x:156"><span class="id" title="variable">x</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">)</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">(</span></a><span class="id" title="keyword">fun</span> <a id="x:157" class="idref" href="#x:157"><span class="id" title="binder">x</span></a> ⇒ <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">(</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Peano.html#pred"><span class="id" title="abbreviation">pred</span></a> 4<a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">)</span></a> <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> <a class="idref" href="Logic.html#x:157"><span class="id" title="variable">x</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">)</span></a>.<br/>
<div class="togglescript" id="proofcontrol3" onclick="toggleDisplay('proof3');toggleDisplay('proofcontrol3')"><span class="show"></span></div>
<div class="proofscript" id="proof3" onclick="toggleDisplay('proof3');toggleDisplay('proofcontrol3')">
<span class="id" title="keyword">Proof</span>. <span class="id" title="tactic">reflexivity</span>. <span class="id" title="keyword">Qed</span>.<br/>
</div>
</div>

<div class="doc">
In common mathematical practice, two functions <span class="inlinecode"><span class="id" title="var">f</span></span> and <span class="inlinecode"><span class="id" title="var">g</span></span> are
    considered equal if they produce the same output on every input:
<br/>
<span class="inlinecode">&nbsp;&nbsp;&nbsp;&nbsp;(<span class="id" title="keyword">∀</span> <span class="id" title="var">x</span>, <span class="id" title="var">f</span> <span class="id" title="var">x</span> = <span class="id" title="var">g</span> <span class="id" title="var">x</span>) → <span class="id" title="var">f</span> = <span class="id" title="var">g</span>
</span>    This is known as the principle of <i>functional extensionality</i>. 
<div class="paragraph"> </div>

 Informally, an "extensional property" is one that pertains to an
    object's observable behavior.  Thus, functional extensionality
    simply means that a function's identity is completely determined
    by what we can observe from it -- i.e., the results we obtain
    after applying it. 
<div class="paragraph"> </div>

 However, functional extensionality is not part of Coq's built-in
    logic.  This means that some apparently "obvious" propositions are
    not provable. 
</div>
<div class="code">

<span class="id" title="keyword">Example</span> <a id="function_equality_ex<sub>2</sub>" class="idref" href="#function_equality_ex<sub>2</sub>"><span class="id" title="definition">function_equality_ex<sub>2</sub></span></a> :<br/>
&nbsp;&nbsp;<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">(</span></a><span class="id" title="keyword">fun</span> <a id="x:158" class="idref" href="#x:158"><span class="id" title="binder">x</span></a> ⇒ <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Peano.html#plus"><span class="id" title="abbreviation">plus</span></a> <a class="idref" href="Logic.html#x:158"><span class="id" title="variable">x</span></a> 1<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">)</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">(</span></a><span class="id" title="keyword">fun</span> <a id="x:159" class="idref" href="#x:159"><span class="id" title="binder">x</span></a> ⇒ <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Peano.html#plus"><span class="id" title="abbreviation">plus</span></a> 1 <a class="idref" href="Logic.html#x:159"><span class="id" title="variable">x</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">)</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;&nbsp;<span class="comment">(*&nbsp;Stuck&nbsp;*)</span><br/>
<span class="id" title="keyword">Abort</span>.<br/>
</div>

<div class="doc">
However, we can add functional extensionality to Coq's core using
    the <span class="inlinecode"><span class="id" title="keyword">Axiom</span></span> command. 
</div>
<div class="code">

<span class="id" title="keyword">Axiom</span> <a id="functional_extensionality" class="idref" href="#functional_extensionality"><span class="id" title="axiom">functional_extensionality</span></a> : <span class="id" title="keyword">∀</span> {<a id="X:160" class="idref" href="#X:160"><span class="id" title="binder">X</span></a> <a id="Y:161" class="idref" href="#Y:161"><span class="id" title="binder">Y</span></a>: <span class="id" title="keyword">Type</span>}<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<a id="f:162" class="idref" href="#f:162"><span class="id" title="binder">f</span></a> <a id="g:163" class="idref" href="#g:163"><span class="id" title="binder">g</span></a> : <a class="idref" href="Logic.html#X:160"><span class="id" title="variable">X</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="Logic.html#Y:161"><span class="id" title="variable">Y</span></a>},<br/>
&nbsp;&nbsp;<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">(</span></a><span class="id" title="keyword">∀</span> (<a id="x:164" class="idref" href="#x:164"><span class="id" title="binder">x</span></a>:<a class="idref" href="Logic.html#X:160"><span class="id" title="variable">X</span></a>), <a class="idref" href="Logic.html#f:162"><span class="id" title="variable">f</span></a> <a class="idref" href="Logic.html#x:164"><span class="id" title="variable">x</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Logic.html#g:163"><span class="id" title="variable">g</span></a> <a class="idref" href="Logic.html#x:164"><span class="id" title="variable">x</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">)</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="Logic.html#f:162"><span class="id" title="variable">f</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Logic.html#g:163"><span class="id" title="variable">g</span></a>.<br/>
</div>

<div class="doc">
Defining something as an <span class="inlinecode"><span class="id" title="keyword">Axiom</span></span> has the same effect as stating a
    theorem and skipping its proof using <span class="inlinecode"><span class="id" title="var">Admitted</span></span>, but it alerts the
    reader that this isn't just something we're going to come back and
    fill in later! 
<div class="paragraph"> </div>

 We can now invoke functional extensionality in proofs: 
</div>
<div class="code">

<span class="id" title="keyword">Example</span> <a id="function_equality_ex<sub>2</sub>" class="idref" href="#function_equality_ex<sub>2</sub>"><span class="id" title="definition">function_equality_ex<sub>2</sub></span></a> :<br/>
&nbsp;&nbsp;<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">(</span></a><span class="id" title="keyword">fun</span> <a id="x:166" class="idref" href="#x:166"><span class="id" title="binder">x</span></a> ⇒ <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Peano.html#plus"><span class="id" title="abbreviation">plus</span></a> <a class="idref" href="Logic.html#x:166"><span class="id" title="variable">x</span></a> 1<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">)</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">(</span></a><span class="id" title="keyword">fun</span> <a id="x:167" class="idref" href="#x:167"><span class="id" title="binder">x</span></a> ⇒ <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Peano.html#plus"><span class="id" title="abbreviation">plus</span></a> 1 <a class="idref" href="Logic.html#x:167"><span class="id" title="variable">x</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">)</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">apply</span> <a class="idref" href="Logic.html#functional_extensionality"><span class="id" title="axiom">functional_extensionality</span></a>. <span class="id" title="tactic">intros</span> <span class="id" title="var">x</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">apply</span> <a class="idref" href="Induction.html#add_comm"><span class="id" title="axiom">add_comm</span></a>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>

<div class="doc">
Naturally, we must be careful when adding new axioms into Coq's
    logic, as this can render it <i>inconsistent</i> -- that is, it may
    become possible to prove every proposition, including <span class="inlinecode"><span class="id" title="var">False</span></span>,
    <span class="inlinecode">2+2=5</span>, etc.!

<div class="paragraph"> </div>

    Unfortunately, there is no simple way of telling whether an axiom
    is safe to add: hard work by highly trained mathematicians is
    often required to establish the consistency of any particular
    combination of axioms.

<div class="paragraph"> </div>

    Fortunately, it is known that adding functional extensionality, in
    particular, <i>is</i> consistent. 
<div class="paragraph"> </div>

 To check whether a particular proof relies on any additional
    axioms, use the <span class="inlinecode"><span class="id" title="keyword">Print</span></span> <span class="inlinecode"><span class="id" title="keyword">Assumptions</span></span> command:
    <span class="inlinecode"><span class="id" title="keyword">Print</span></span> <span class="inlinecode"><span class="id" title="keyword">Assumptions</span></span> <span class="inlinecode"><span class="id" title="var">function_equality_ex<sub>2</sub></span></span>. 
</div>
<div class="code">

<span class="comment">(*&nbsp;===&gt;<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Axioms:<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;functional_extensionality&nbsp;:<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;forall&nbsp;(X&nbsp;Y&nbsp;:&nbsp;Type)&nbsp;(f&nbsp;g&nbsp;:&nbsp;X&nbsp;<span class="nowrap"><span style='font-size:85%;'><span style='vertical-align:5%;'><span style='letter-spacing:-.2em;'>-</span></span>&gt;</span></span>&nbsp;Y),<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(forall&nbsp;x&nbsp;:&nbsp;X,&nbsp;f&nbsp;x&nbsp;=&nbsp;g&nbsp;x)&nbsp;<span class="nowrap"><span style='font-size:85%;'><span style='vertical-align:5%;'><span style='letter-spacing:-.2em;'>-</span></span>&gt;</span></span>&nbsp;f&nbsp;=&nbsp;g&nbsp;*)</span><br/>
</div>

<div class="doc">
(You may also see <span class="inlinecode"><span class="id" title="var">add_comm</span></span> listed as an assumption, depending
    on whether the copy of <span class="inlinecode"><span class="id" title="var">Tactics.v</span></span> in the local directory has the
    proof of <span class="inlinecode"><span class="id" title="var">add_comm</span></span> filled in.) 
<div class="paragraph"> </div>

<a id="lab197"></a><h4 class="section">Exercise: 4 stars, standard (tr_rev_correct)</h4>
 One problem with the definition of the list-reversing function
    <span class="inlinecode"><span class="id" title="var">rev</span></span> that we have is that it performs a call to <span class="inlinecode"><span class="id" title="var">app</span></span> on each
    step; running <span class="inlinecode"><span class="id" title="var">app</span></span> takes time asymptotically linear in the size
    of the list, which means that <span class="inlinecode"><span class="id" title="var">rev</span></span> is asymptotically quadratic.
    We can improve this with the following definitions: 
</div>
<div class="code">

<span class="id" title="keyword">Fixpoint</span> <a id="rev_append" class="idref" href="#rev_append"><span class="id" title="definition">rev_append</span></a> {<a id="X:168" class="idref" href="#X:168"><span class="id" title="binder">X</span></a>} (<a id="l<sub>1</sub>:169" class="idref" href="#l<sub>1</sub>:169"><span class="id" title="binder">l<sub>1</sub></span></a> <a id="l<sub>2</sub>:170" class="idref" href="#l<sub>2</sub>:170"><span class="id" title="binder">l<sub>2</sub></span></a> : <a class="idref" href="Poly.html#list"><span class="id" title="inductive">list</span></a> <a class="idref" href="Logic.html#X:168"><span class="id" title="variable">X</span></a>) : <a class="idref" href="Poly.html#list"><span class="id" title="inductive">list</span></a> <a class="idref" href="Logic.html#X:168"><span class="id" title="variable">X</span></a> :=<br/>
&nbsp;&nbsp;<span class="id" title="keyword">match</span> <a class="idref" href="Logic.html#l<sub>1</sub>:169"><span class="id" title="variable">l<sub>1</sub></span></a> <span class="id" title="keyword">with</span><br/>
&nbsp;&nbsp;| <a class="idref" href="Poly.html#2c60282cbb04e070c60ae01e76f3865a"><span class="id" title="notation">[]</span></a> ⇒ <a class="idref" href="Logic.html#l<sub>2</sub>:170"><span class="id" title="variable">l<sub>2</sub></span></a><br/>
&nbsp;&nbsp;| <span class="id" title="var">x</span> <a class="idref" href="Poly.html#:::x_'::'_x"><span class="id" title="notation">::</span></a> <span class="id" title="var">l<sub>1</sub>'</span> ⇒ <a class="idref" href="Logic.html#rev_append:171"><span class="id" title="definition">rev_append</span></a> <span class="id" title="var">l<sub>1</sub>'</span> (<span class="id" title="var">x</span> <a class="idref" href="Poly.html#:::x_'::'_x"><span class="id" title="notation">::</span></a> <a class="idref" href="Logic.html#l<sub>2</sub>:170"><span class="id" title="variable">l<sub>2</sub></span></a>)<br/>
&nbsp;&nbsp;<span class="id" title="keyword">end</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Definition</span> <a id="tr_rev" class="idref" href="#tr_rev"><span class="id" title="definition">tr_rev</span></a> {<a id="X:173" class="idref" href="#X:173"><span class="id" title="binder">X</span></a>} (<a id="l:174" class="idref" href="#l:174"><span class="id" title="binder">l</span></a> : <a class="idref" href="Poly.html#list"><span class="id" title="inductive">list</span></a> <a class="idref" href="Logic.html#X:173"><span class="id" title="variable">X</span></a>) : <a class="idref" href="Poly.html#list"><span class="id" title="inductive">list</span></a> <a class="idref" href="Logic.html#X:173"><span class="id" title="variable">X</span></a> :=<br/>
&nbsp;&nbsp;<a class="idref" href="Logic.html#rev_append"><span class="id" title="definition">rev_append</span></a> <a class="idref" href="Logic.html#l:174"><span class="id" title="variable">l</span></a> <a class="idref" href="Poly.html#2c60282cbb04e070c60ae01e76f3865a"><span class="id" title="notation">[]</span></a>.<br/>
</div>

<div class="doc">
This version of <span class="inlinecode"><span class="id" title="var">rev</span></span> is said to be <i>tail-recursive</i>, because the
    recursive call to the function is the last operation that needs to
    be performed (i.e., we don't have to execute <span class="inlinecode">++</span> after the
    recursive call); a decent compiler will generate very efficient
    code in this case.

<div class="paragraph"> </div>

    Prove that the two definitions are indeed equivalent. 
</div>
<div class="code">

<span class="id" title="keyword">Theorem</span> <a id="tr_rev_correct" class="idref" href="#tr_rev_correct"><span class="id" title="lemma">tr_rev_correct</span></a> : <span class="id" title="keyword">∀</span> <a id="X:175" class="idref" href="#X:175"><span class="id" title="binder">X</span></a>, @<a class="idref" href="Logic.html#tr_rev"><span class="id" title="definition">tr_rev</span></a> <a class="idref" href="Logic.html#X:175"><span class="id" title="variable">X</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> @<a class="idref" href="Poly.html#rev"><span class="id" title="definition">rev</span></a> <a class="idref" href="Logic.html#X:175"><span class="id" title="variable">X</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
<span class="comment">(*&nbsp;FILL&nbsp;IN&nbsp;HERE&nbsp;*)</span> <span class="id" title="var">Admitted</span>.<br/>
<font size=-2>&#9744;</font>
</div>

<div class="doc"> 
<div class="paragraph"> </div>

<a id="lab198"></a><h2 class="section">Propositions vs. Booleans</h2>
 We've seen two different ways of expressing logical claims in Coq:
    with <i>booleans</i> (of type <span class="inlinecode"><span class="id" title="var">bool</span></span>), and with <i>propositions</i> (of type
    <span class="inlinecode"><span class="id" title="keyword">Prop</span></span>).

<div class="paragraph"> </div>

    Here are the key differences between <span class="inlinecode"><span class="id" title="var">bool</span></span> and <span class="inlinecode"><span class="id" title="keyword">Prop</span></span>:
<pre>
                                           bool     Prop
                                           ====     ====
           decidable?                      yes       no
           useable with match?             yes       no
           equalities rewritable?          no        yes
</pre>

<div class="paragraph"> </div>

 The most essential difference between the two worlds is
    <i>decidability</i>.  Every Coq expression of type <span class="inlinecode"><span class="id" title="var">bool</span></span> can be
    simplified in a finite number of steps to either <span class="inlinecode"><span class="id" title="var">true</span></span> or
    <span class="inlinecode"><span class="id" title="var">false</span></span> -- i.e., there is a terminating mechanical procedure for
    deciding whether or not it is <span class="inlinecode"><span class="id" title="var">true</span></span>.  This means that, for
    example, the type <span class="inlinecode"><span class="id" title="var">nat</span></span> <span class="inlinecode">→</span> <span class="inlinecode"><span class="id" title="var">bool</span></span> is inhabited only by functions
    that, given a <span class="inlinecode"><span class="id" title="var">nat</span></span>, always return either <span class="inlinecode"><span class="id" title="var">true</span></span> or <span class="inlinecode"><span class="id" title="var">false</span></span>; and
    this, in turn, means that there is no function in <span class="inlinecode"><span class="id" title="var">nat</span></span> <span class="inlinecode">→</span> <span class="inlinecode"><span class="id" title="var">bool</span></span>
    that checks whether a given number is the code of a terminating
    Turing machine.  By contrast, the type <span class="inlinecode"><span class="id" title="keyword">Prop</span></span> includes both
    decidable and undecidable mathematical propositions; in
    particular, the type <span class="inlinecode"><span class="id" title="var">nat</span></span> <span class="inlinecode">→</span> <span class="inlinecode"><span class="id" title="keyword">Prop</span></span> does contain functions
    representing properties like "the nth Turing machine halts."

<div class="paragraph"> </div>

    The second row in the table above follow directly from this
    essential difference.  To evaluate a pattern match (or
    conditional) on a boolean, we need to know whether the scrutinee
    evaluates to <span class="inlinecode"><span class="id" title="var">true</span></span> or <span class="inlinecode"><span class="id" title="var">false</span></span>; this only works for <span class="inlinecode"><span class="id" title="var">bool</span></span>, not
    <span class="inlinecode"><span class="id" title="keyword">Prop</span></span>.  The third row highlights another important practical
    difference: equality functions like <span class="inlinecode"><span class="id" title="var">eqb_nat</span></span> that return a
    boolean cannot be used directly to justify rewriting, whereas
    the propositional <span class="inlinecode"><span class="id" title="var">eq</span></span> can be. 
<div class="paragraph"> </div>

<a id="lab199"></a><h2 class="section">Working with Decidable Properties</h2>

<div class="paragraph"> </div>

 Since <span class="inlinecode"><span class="id" title="keyword">Prop</span></span> includes <i>both</i> decidable and undecidable properties,
    we have two choices when when we are dealing with a property that
    happens to be decidable: we can express it as a boolean
    computation or as a function into <span class="inlinecode"><span class="id" title="keyword">Prop</span></span>.

<div class="paragraph"> </div>

    For instance, to claim that a number <span class="inlinecode"><span class="id" title="var">n</span></span> is even, we can say
    either... 
<div class="paragraph"> </div>

 ... that <span class="inlinecode"><span class="id" title="var">even</span></span> <span class="inlinecode"><span class="id" title="var">n</span></span> evaluates to <span class="inlinecode"><span class="id" title="var">true</span></span>... 
</div>
<div class="code">
<span class="id" title="keyword">Example</span> <a id="even_42_bool" class="idref" href="#even_42_bool"><span class="id" title="definition">even_42_bool</span></a> : <a class="idref" href="Basics.html#even"><span class="id" title="definition">even</span></a> 42 <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Basics.html#true"><span class="id" title="constructor">true</span></a>.<br/>
<div class="togglescript" id="proofcontrol4" onclick="toggleDisplay('proof4');toggleDisplay('proofcontrol4')"><span class="show"></span></div>
<div class="proofscript" id="proof4" onclick="toggleDisplay('proof4');toggleDisplay('proofcontrol4')">
<span class="id" title="keyword">Proof</span>. <span class="id" title="tactic">reflexivity</span>. <span class="id" title="keyword">Qed</span>.<br/>
</div>
</div>

<div class="doc">
... or that there exists some <span class="inlinecode"><span class="id" title="var">k</span></span> such that <span class="inlinecode"><span class="id" title="var">n</span></span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" title="var">double</span></span> <span class="inlinecode"><span class="id" title="var">k</span></span>. 
</div>
<div class="code">
<span class="id" title="keyword">Example</span> <a id="even_42_prop" class="idref" href="#even_42_prop"><span class="id" title="definition">even_42_prop</span></a> : <a class="idref" href="Logic.html#Even"><span class="id" title="definition">Even</span></a> 42.<br/>
<div class="togglescript" id="proofcontrol5" onclick="toggleDisplay('proof5');toggleDisplay('proofcontrol5')"><span class="show"></span></div>
<div class="proofscript" id="proof5" onclick="toggleDisplay('proof5');toggleDisplay('proofcontrol5')">
<span class="id" title="keyword">Proof</span>. <span class="id" title="tactic">unfold</span> <a class="idref" href="Logic.html#Even"><span class="id" title="definition">Even</span></a>. <span class="id" title="tactic">∃</span> 21. <span class="id" title="tactic">reflexivity</span>. <span class="id" title="keyword">Qed</span>.<br/>
</div>
</div>

<div class="doc">
Of course, it would be pretty strange if these two
    characterizations of evenness did not describe the same set of
    natural numbers!  Fortunately, we can prove that they do... 
<div class="paragraph"> </div>

 We first need two helper lemmas. 
</div>
<div class="code">
<span class="id" title="keyword">Lemma</span> <a id="even_double" class="idref" href="#even_double"><span class="id" title="lemma">even_double</span></a> : <span class="id" title="keyword">∀</span> <a id="k:176" class="idref" href="#k:176"><span class="id" title="binder">k</span></a>, <a class="idref" href="Basics.html#even"><span class="id" title="definition">even</span></a> (<a class="idref" href="Induction.html#double"><span class="id" title="definition">double</span></a> <a class="idref" href="Logic.html#k:176"><span class="id" title="variable">k</span></a>) <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Basics.html#true"><span class="id" title="constructor">true</span></a>.<br/>
<div class="togglescript" id="proofcontrol6" onclick="toggleDisplay('proof6');toggleDisplay('proofcontrol6')"><span class="show"></span></div>
<div class="proofscript" id="proof6" onclick="toggleDisplay('proof6');toggleDisplay('proofcontrol6')">
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">intros</span> <span class="id" title="var">k</span>. <span class="id" title="tactic">induction</span> <span class="id" title="var">k</span> <span class="id" title="keyword">as</span> [|<span class="id" title="var">k'</span> <span class="id" title="var">IHk'</span>].<br/>
&nbsp;&nbsp;- <span class="id" title="tactic">reflexivity</span>.<br/>
&nbsp;&nbsp;- <span class="id" title="tactic">simpl</span>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IHk'</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>
</div>

<div class="doc">
<a id="lab200"></a><h4 class="section">Exercise: 3 stars, standard (even_double_conv)</h4>

</div>
<div class="code">
<span class="id" title="keyword">Lemma</span> <a id="even_double_conv" class="idref" href="#even_double_conv"><span class="id" title="lemma">even_double_conv</span></a> : <span class="id" title="keyword">∀</span> <a id="n:177" class="idref" href="#n:177"><span class="id" title="binder">n</span></a>, <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#a883bdd010993579f99d60b3775bcf54"><span class="id" title="notation">∃</span></a> <a id="k:178" class="idref" href="#k:178"><span class="id" title="binder">k</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#a883bdd010993579f99d60b3775bcf54"><span class="id" title="notation">,</span></a><br/>
&nbsp;&nbsp;<a class="idref" href="Logic.html#n:177"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <span class="id" title="keyword">if</span> <a class="idref" href="Basics.html#even"><span class="id" title="definition">even</span></a> <a class="idref" href="Logic.html#n:177"><span class="id" title="variable">n</span></a> <span class="id" title="keyword">then</span> <a class="idref" href="Induction.html#double"><span class="id" title="definition">double</span></a> <a class="idref" href="Logic.html#k:178"><span class="id" title="variable">k</span></a> <span class="id" title="keyword">else</span> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#S"><span class="id" title="constructor">S</span></a> (<a class="idref" href="Induction.html#double"><span class="id" title="definition">double</span></a> <a class="idref" href="Logic.html#k:178"><span class="id" title="variable">k</span></a>).<br/>
<div class="togglescript" id="proofcontrol7" onclick="toggleDisplay('proof7');toggleDisplay('proofcontrol7')"><span class="show"></span></div>
<div class="proofscript" id="proof7" onclick="toggleDisplay('proof7');toggleDisplay('proofcontrol7')">
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="comment">(*&nbsp;Hint:&nbsp;Use&nbsp;the&nbsp;<span class="inlinecode"><span class="id" title="var">even_S</span></span>&nbsp;lemma&nbsp;from&nbsp;<span class="inlinecode"><span class="id" title="var">Induction.v</span></span>.&nbsp;*)</span><br/>
&nbsp;&nbsp;<span class="comment">(*&nbsp;FILL&nbsp;IN&nbsp;HERE&nbsp;*)</span> <span class="id" title="var">Admitted</span>.<br/>
<font size=-2>&#9744;</font>
</div>


<br/>
</div>

<div class="doc">
Now the main theorem: 
</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <a id="even_bool_prop" class="idref" href="#even_bool_prop"><span class="id" title="lemma">even_bool_prop</span></a> : <span class="id" title="keyword">∀</span> <a id="n:179" class="idref" href="#n:179"><span class="id" title="binder">n</span></a>,<br/>
&nbsp;&nbsp;<a class="idref" href="Basics.html#even"><span class="id" title="definition">even</span></a> <a class="idref" href="Logic.html#n:179"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Basics.html#true"><span class="id" title="constructor">true</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'&lt;-&gt;'_x"><span class="id" title="notation">↔</span></a> <a class="idref" href="Logic.html#Even"><span class="id" title="definition">Even</span></a> <a class="idref" href="Logic.html#n:179"><span class="id" title="variable">n</span></a>.<br/>
<div class="togglescript" id="proofcontrol8" onclick="toggleDisplay('proof8');toggleDisplay('proofcontrol8')"><span class="show"></span></div>
<div class="proofscript" id="proof8" onclick="toggleDisplay('proof8');toggleDisplay('proofcontrol8')">
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">intros</span> <span class="id" title="var">n</span>. <span class="id" title="tactic">split</span>.<br/>
&nbsp;&nbsp;- <span class="id" title="tactic">intros</span> <span class="id" title="var">H</span>. <span class="id" title="tactic">destruct</span> (<a class="idref" href="Logic.html#even_double_conv"><span class="id" title="axiom">even_double_conv</span></a> <span class="id" title="var">n</span>) <span class="id" title="keyword">as</span> [<span class="id" title="var">k</span> <span class="id" title="var">Hk</span>].<br/>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="id" title="tactic">rewrite</span> <span class="id" title="var">Hk</span>. <span class="id" title="tactic">rewrite</span> <span class="id" title="var">H</span>. <span class="id" title="tactic">∃</span> <span class="id" title="var">k</span>. <span class="id" title="tactic">reflexivity</span>.<br/>
&nbsp;&nbsp;- <span class="id" title="tactic">intros</span> [<span class="id" title="var">k</span> <span class="id" title="var">Hk</span>]. <span class="id" title="tactic">rewrite</span> <span class="id" title="var">Hk</span>. <span class="id" title="tactic">apply</span> <a class="idref" href="Logic.html#even_double"><span class="id" title="lemma">even_double</span></a>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>
</div>

<div class="doc">
In view of this theorem, we say that the boolean computation
    <span class="inlinecode"><span class="id" title="var">even</span></span> <span class="inlinecode"><span class="id" title="var">n</span></span> is <i>reflected</i> in the truth of the proposition
    <span class="inlinecode"><span class="id" title="tactic">∃</span></span> <span class="inlinecode"><span class="id" title="var">k</span>,</span> <span class="inlinecode"><span class="id" title="var">n</span></span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" title="var">double</span></span> <span class="inlinecode"><span class="id" title="var">k</span></span>. 
<div class="paragraph"> </div>

 Similarly, to state that two numbers <span class="inlinecode"><span class="id" title="var">n</span></span> and <span class="inlinecode"><span class="id" title="var">m</span></span> are equal, we can
    say either
<ul class="doclist">
<li> (1) that <span class="inlinecode"><span class="id" title="var">n</span></span> <span class="inlinecode">=?</span> <span class="inlinecode"><span class="id" title="var">m</span></span> returns <span class="inlinecode"><span class="id" title="var">true</span></span>, or

</li>
<li> (2) that <span class="inlinecode"><span class="id" title="var">n</span></span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" title="var">m</span></span>.

</li>
</ul>
    Again, these two notions are equivalent. 
</div>
<div class="code">

<span class="id" title="keyword">Theorem</span> <a id="eqb_eq" class="idref" href="#eqb_eq"><span class="id" title="lemma">eqb_eq</span></a> : <span class="id" title="keyword">∀</span> <a id="n<sub>1</sub>:180" class="idref" href="#n<sub>1</sub>:180"><span class="id" title="binder">n<sub>1</sub></span></a> <a id="n<sub>2</sub>:181" class="idref" href="#n<sub>2</sub>:181"><span class="id" title="binder">n<sub>2</sub></span></a> : <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#nat"><span class="id" title="inductive">nat</span></a>,<br/>
&nbsp;&nbsp;<a class="idref" href="Logic.html#n<sub>1</sub>:180"><span class="id" title="variable">n<sub>1</sub></span></a> <a class="idref" href="Basics.html#ad2ec4e405f68c46c0a176e3e94ae2e<sub>3</sub>"><span class="id" title="notation">=?</span></a> <a class="idref" href="Logic.html#n<sub>2</sub>:181"><span class="id" title="variable">n<sub>2</sub></span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Basics.html#true"><span class="id" title="constructor">true</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'&lt;-&gt;'_x"><span class="id" title="notation">↔</span></a> <a class="idref" href="Logic.html#n<sub>1</sub>:180"><span class="id" title="variable">n<sub>1</sub></span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Logic.html#n<sub>2</sub>:181"><span class="id" title="variable">n<sub>2</sub></span></a>.<br/>
<div class="togglescript" id="proofcontrol9" onclick="toggleDisplay('proof9');toggleDisplay('proofcontrol9')"><span class="show"></span></div>
<div class="proofscript" id="proof9" onclick="toggleDisplay('proof9');toggleDisplay('proofcontrol9')">
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">intros</span> <span class="id" title="var">n<sub>1</sub></span> <span class="id" title="var">n<sub>2</sub></span>. <span class="id" title="tactic">split</span>.<br/>
&nbsp;&nbsp;- <span class="id" title="tactic">apply</span> <a class="idref" href="Tactics.html#eqb_true"><span class="id" title="axiom">eqb_true</span></a>.<br/>
&nbsp;&nbsp;- <span class="id" title="tactic">intros</span> <span class="id" title="var">H</span>. <span class="id" title="tactic">rewrite</span> <span class="id" title="var">H</span>. <span class="id" title="tactic">rewrite</span> <a class="idref" href="Induction.html#eqb_refl"><span class="id" title="axiom">eqb_refl</span></a>. <span class="id" title="tactic">reflexivity</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>
</div>

<div class="doc">
Even when the boolean and propositional formulations of a claim
    are equivalent from a purely logical perspective, they are often
    not equivalent from the point of view of convenience for some
    specific purpose. 
<div class="paragraph"> </div>

 In the case of even numbers above, when proving the
    backwards direction of <span class="inlinecode"><span class="id" title="var">even_bool_prop</span></span> (i.e., <span class="inlinecode"><span class="id" title="var">even_double</span></span>,
    going from the propositional to the boolean claim), we used a
    simple induction on <span class="inlinecode"><span class="id" title="var">k</span></span>.  On the other hand, the converse (the
    <span class="inlinecode"><span class="id" title="var">even_double_conv</span></span> exercise) required a clever generalization,
    since we can't directly prove <span class="inlinecode">(<span class="id" title="var">even</span></span> <span class="inlinecode"><span class="id" title="var">n</span></span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" title="var">true</span>)</span> <span class="inlinecode">→</span> <span class="inlinecode"><span class="id" title="var">Even</span></span> <span class="inlinecode"><span class="id" title="var">n</span></span>. 
<div class="paragraph"> </div>

 We cannot <i>test</i> whether a <span class="inlinecode"><span class="id" title="keyword">Prop</span></span> is true or not in a
    function definition; as a consequence, the following code fragment
    is rejected: 
</div>
<div class="code">

<span class="id" title="var">Fail</span><br/>
<span class="id" title="keyword">Definition</span> <a id="is_even_prime" class="idref" href="#is_even_prime"><span class="id" title="definition">is_even_prime</span></a> <a id="n:182" class="idref" href="#n:182"><span class="id" title="binder">n</span></a> :=<br/>
&nbsp;&nbsp;<span class="id" title="keyword">if</span> <a class="idref" href="Logic.html#n:182"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> 2 <span class="id" title="keyword">then</span> <a class="idref" href="Basics.html#true"><span class="id" title="constructor">true</span></a><br/>
&nbsp;&nbsp;<span class="id" title="keyword">else</span> <a class="idref" href="Basics.html#false"><span class="id" title="constructor">false</span></a>.<br/>
</div>

<div class="doc">
Coq complains that <span class="inlinecode"><span class="id" title="var">n</span></span> <span class="inlinecode">=</span> <span class="inlinecode">2</span> has type <span class="inlinecode"><span class="id" title="keyword">Prop</span></span>, while it expects
    an element of <span class="inlinecode"><span class="id" title="var">bool</span></span> (or some other inductive type with two
    elements).  The reason has to do with the <i>computational</i> nature
    of Coq's core language, which is designed so that every function
    it can express is computable and total.  One reason for this is to
    allow the extraction of executable programs from Coq developments.
    As a consequence, <span class="inlinecode"><span class="id" title="keyword">Prop</span></span> in Coq does <i>not</i> have a universal case
    analysis operation telling whether any given proposition is true
    or false, since such an operation would allow us to write
    non-computable functions.

<div class="paragraph"> </div>

    Beyond the fact that non-computable properties are impossible in
    general to phrase as boolean computations, even many <i>computable</i>
    properties are easier to express using <span class="inlinecode"><span class="id" title="keyword">Prop</span></span> than <span class="inlinecode"><span class="id" title="var">bool</span></span>, since
    recursive function definitions in Coq are subject to significant
    restrictions.  For instance, the next chapter shows how to define
    the property that a regular expression matches a given string
    using <span class="inlinecode"><span class="id" title="keyword">Prop</span></span>.  Doing the same with <span class="inlinecode"><span class="id" title="var">bool</span></span> would amount to writing
    a regular expression matching algorithm, which would be more
    complicated, harder to understand, and harder to reason about than
    a simple (non-algorithmic) definition of this property.

<div class="paragraph"> </div>

    Conversely, an important side benefit of stating facts using
    booleans is enabling some proof automation through computation
    with Coq terms, a technique known as <i>proof by reflection</i>.

<div class="paragraph"> </div>

    Consider the following statement: 
</div>
<div class="code">

<span class="id" title="keyword">Example</span> <a id="even_1000" class="idref" href="#even_1000"><span class="id" title="definition">even_1000</span></a> : <a class="idref" href="Logic.html#Even"><span class="id" title="definition">Even</span></a> 1000.<br/>
</div>

<div class="doc">
The most direct way to prove this is to give the value of <span class="inlinecode"><span class="id" title="var">k</span></span>
    explicitly. 
</div>
<div class="code">

<span class="id" title="keyword">Proof</span>. <span class="id" title="tactic">unfold</span> <a class="idref" href="Logic.html#Even"><span class="id" title="definition">Even</span></a>. <span class="id" title="tactic">∃</span> 500. <span class="id" title="tactic">reflexivity</span>. <span class="id" title="keyword">Qed</span>.<br/>
</div>

<div class="doc">
The proof of the corresponding boolean statement is even
    simpler (because we don't have to invent the witness: Coq's
    computation mechanism does it for us!). 
</div>
<div class="code">

<span class="id" title="keyword">Example</span> <a id="even_1000'" class="idref" href="#even_1000'"><span class="id" title="definition">even_1000'</span></a> : <a class="idref" href="Basics.html#even"><span class="id" title="definition">even</span></a> 1000 <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Basics.html#true"><span class="id" title="constructor">true</span></a>.<br/>
<span class="id" title="keyword">Proof</span>. <span class="id" title="tactic">reflexivity</span>. <span class="id" title="keyword">Qed</span>.<br/>
</div>

<div class="doc">
What is interesting is that, since the two notions are equivalent,
    we can use the boolean formulation to prove the other one without
    mentioning the value 500 explicitly: 
</div>
<div class="code">

<span class="id" title="keyword">Example</span> <a id="even_1000''" class="idref" href="#even_1000''"><span class="id" title="definition">even_1000''</span></a> : <a class="idref" href="Logic.html#Even"><span class="id" title="definition">Even</span></a> 1000.<br/>
<span class="id" title="keyword">Proof</span>. <span class="id" title="tactic">apply</span> <a class="idref" href="Logic.html#even_bool_prop"><span class="id" title="lemma">even_bool_prop</span></a>. <span class="id" title="tactic">reflexivity</span>. <span class="id" title="keyword">Qed</span>.<br/>
</div>

<div class="doc">
Although we haven't gained much in terms of proof-script
    size in this case, larger proofs can often be made considerably
    simpler by the use of reflection.  As an extreme example, a famous
    Coq proof of the even more famous <i>4-color theorem</i> uses
    reflection to reduce the analysis of hundreds of different cases
    to a boolean computation. 
<div class="paragraph"> </div>

 Another notable difference is that the negation of a "boolean
    fact" is straightforward to state and prove: simply flip the
    expected boolean result. 
</div>
<div class="code">

<span class="id" title="keyword">Example</span> <a id="not_even_1001" class="idref" href="#not_even_1001"><span class="id" title="definition">not_even_1001</span></a> : <a class="idref" href="Basics.html#even"><span class="id" title="definition">even</span></a> 1001 <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Basics.html#false"><span class="id" title="constructor">false</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="comment">(*&nbsp;WORKED&nbsp;IN&nbsp;CLASS&nbsp;*)</span><br/>
&nbsp;&nbsp;<span class="id" title="tactic">reflexivity</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>

<div class="doc">
In contrast, propositional negation can be more difficult
    to work with directly. 
</div>
<div class="code">

<span class="id" title="keyword">Example</span> <a id="not_even_1001'" class="idref" href="#not_even_1001'"><span class="id" title="definition">not_even_1001'</span></a> : <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#63a68285c81db8f9bc456233bb9ed181"><span class="id" title="notation">~(</span></a><a class="idref" href="Logic.html#Even"><span class="id" title="definition">Even</span></a> 1001<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#63a68285c81db8f9bc456233bb9ed181"><span class="id" title="notation">)</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="comment">(*&nbsp;WORKED&nbsp;IN&nbsp;CLASS&nbsp;*)</span><br/>
&nbsp;&nbsp;<span class="id" title="tactic">rewrite</span> &lt;- <a class="idref" href="Logic.html#even_bool_prop"><span class="id" title="lemma">even_bool_prop</span></a>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">unfold</span> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#not"><span class="id" title="definition">not</span></a>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">simpl</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">intro</span> <span class="id" title="var">H</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">discriminate</span> <span class="id" title="var">H</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>

<div class="doc">
Equality provides a complementary example, where it is sometimes
    easier to work in the propositional world.

<div class="paragraph"> </div>

    Knowing that <span class="inlinecode">(<span class="id" title="var">n</span></span> <span class="inlinecode">=?</span> <span class="inlinecode"><span class="id" title="var">m</span>)</span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" title="var">true</span></span> is generally of little direct help in
    the middle of a proof involving <span class="inlinecode"><span class="id" title="var">n</span></span> and <span class="inlinecode"><span class="id" title="var">m</span></span>; however, if we
    convert the statement to the equivalent form <span class="inlinecode"><span class="id" title="var">n</span></span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" title="var">m</span></span>, we can
    rewrite with it. 
</div>
<div class="code">

<span class="id" title="keyword">Lemma</span> <a id="plus_eqb_example" class="idref" href="#plus_eqb_example"><span class="id" title="lemma">plus_eqb_example</span></a> : <span class="id" title="keyword">∀</span> <a id="n:183" class="idref" href="#n:183"><span class="id" title="binder">n</span></a> <a id="m:184" class="idref" href="#m:184"><span class="id" title="binder">m</span></a> <a id="p:185" class="idref" href="#p:185"><span class="id" title="binder">p</span></a> : <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#nat"><span class="id" title="inductive">nat</span></a>,<br/>
&nbsp;&nbsp;<a class="idref" href="Logic.html#n:183"><span class="id" title="variable">n</span></a> <a class="idref" href="Basics.html#ad2ec4e405f68c46c0a176e3e94ae2e<sub>3</sub>"><span class="id" title="notation">=?</span></a> <a class="idref" href="Logic.html#m:184"><span class="id" title="variable">m</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Basics.html#true"><span class="id" title="constructor">true</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="Logic.html#n:183"><span class="id" title="variable">n</span></a> <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> <a class="idref" href="Logic.html#p:185"><span class="id" title="variable">p</span></a> <a class="idref" href="Basics.html#ad2ec4e405f68c46c0a176e3e94ae2e<sub>3</sub>"><span class="id" title="notation">=?</span></a> <a class="idref" href="Logic.html#m:184"><span class="id" title="variable">m</span></a> <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> <a class="idref" href="Logic.html#p:185"><span class="id" title="variable">p</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Basics.html#true"><span class="id" title="constructor">true</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="comment">(*&nbsp;WORKED&nbsp;IN&nbsp;CLASS&nbsp;*)</span><br/>
&nbsp;&nbsp;<span class="id" title="tactic">intros</span> <span class="id" title="var">n</span> <span class="id" title="var">m</span> <span class="id" title="var">p</span> <span class="id" title="var">H</span>.<br/>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="id" title="tactic">rewrite</span> <a class="idref" href="Logic.html#eqb_eq"><span class="id" title="lemma">eqb_eq</span></a> <span class="id" title="keyword">in</span> <span class="id" title="var">H</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">rewrite</span> <span class="id" title="var">H</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">rewrite</span> <a class="idref" href="Logic.html#eqb_eq"><span class="id" title="lemma">eqb_eq</span></a>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">reflexivity</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>

<div class="doc">
We won't discuss reflection any further for the moment, but it
    serves as a good example showing the complementary strengths of
    booleans and general propositions, and being able to cross back
    and forth between the boolean and propositional worlds will often
    be convenient in later chapters. 
<div class="paragraph"> </div>

<a id="lab201"></a><h4 class="section">Exercise: 2 stars, standard (logical_connectives)</h4>
 The following theorems relate the propositional connectives studied
    in this chapter to the corresponding boolean operations. 
</div>
<div class="code">

<span class="id" title="keyword">Theorem</span> <a id="andb_true_iff" class="idref" href="#andb_true_iff"><span class="id" title="lemma">andb_true_iff</span></a> : <span class="id" title="keyword">∀</span> <a id="b<sub>1</sub>:186" class="idref" href="#b<sub>1</sub>:186"><span class="id" title="binder">b<sub>1</sub></span></a> <a id="b<sub>2</sub>:187" class="idref" href="#b<sub>2</sub>:187"><span class="id" title="binder">b<sub>2</sub></span></a>:<a class="idref" href="Basics.html#bool"><span class="id" title="inductive">bool</span></a>,<br/>
&nbsp;&nbsp;<a class="idref" href="Logic.html#b<sub>1</sub>:186"><span class="id" title="variable">b<sub>1</sub></span></a> <a class="idref" href="Basics.html#:::x_'&amp;&amp;'_x"><span class="id" title="notation">&amp;&amp;</span></a> <a class="idref" href="Logic.html#b<sub>2</sub>:187"><span class="id" title="variable">b<sub>2</sub></span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Basics.html#true"><span class="id" title="constructor">true</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'&lt;-&gt;'_x"><span class="id" title="notation">↔</span></a> <a class="idref" href="Logic.html#b<sub>1</sub>:186"><span class="id" title="variable">b<sub>1</sub></span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Basics.html#true"><span class="id" title="constructor">true</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#ba2b0e492d2b4675a0acf3ea92aabadd"><span class="id" title="notation">∧</span></a> <a class="idref" href="Logic.html#b<sub>2</sub>:187"><span class="id" title="variable">b<sub>2</sub></span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Basics.html#true"><span class="id" title="constructor">true</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="comment">(*&nbsp;FILL&nbsp;IN&nbsp;HERE&nbsp;*)</span> <span class="id" title="var">Admitted</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Theorem</span> <a id="orb_true_iff" class="idref" href="#orb_true_iff"><span class="id" title="lemma">orb_true_iff</span></a> : <span class="id" title="keyword">∀</span> <a id="b<sub>1</sub>:188" class="idref" href="#b<sub>1</sub>:188"><span class="id" title="binder">b<sub>1</sub></span></a> <a id="b<sub>2</sub>:189" class="idref" href="#b<sub>2</sub>:189"><span class="id" title="binder">b<sub>2</sub></span></a>,<br/>
&nbsp;&nbsp;<a class="idref" href="Logic.html#b<sub>1</sub>:188"><span class="id" title="variable">b<sub>1</sub></span></a> <a class="idref" href="Basics.html#34428c8531fd724748c0ebf19a35c764"><span class="id" title="notation">||</span></a> <a class="idref" href="Logic.html#b<sub>2</sub>:189"><span class="id" title="variable">b<sub>2</sub></span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Basics.html#true"><span class="id" title="constructor">true</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'&lt;-&gt;'_x"><span class="id" title="notation">↔</span></a> <a class="idref" href="Logic.html#b<sub>1</sub>:188"><span class="id" title="variable">b<sub>1</sub></span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Basics.html#true"><span class="id" title="constructor">true</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#f031fe1957c4a4a8e217aa46af2b4e<sub>25</sub>"><span class="id" title="notation">∨</span></a> <a class="idref" href="Logic.html#b<sub>2</sub>:189"><span class="id" title="variable">b<sub>2</sub></span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Basics.html#true"><span class="id" title="constructor">true</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="comment">(*&nbsp;FILL&nbsp;IN&nbsp;HERE&nbsp;*)</span> <span class="id" title="var">Admitted</span>.<br/>
<font size=-2>&#9744;</font>
</div>

<div class="doc"> 
<div class="paragraph"> </div>

<a id="lab202"></a><h4 class="section">Exercise: 1 star, standard (eqb_neq)</h4>
 The following theorem is an alternate "negative" formulation of
    <span class="inlinecode"><span class="id" title="var">eqb_eq</span></span> that is more convenient in certain situations.  (We'll see
    examples in later chapters.)  Hint: <span class="inlinecode"><span class="id" title="var">not_true_iff_false</span></span>. 
</div>
<div class="code">

<span class="id" title="keyword">Theorem</span> <a id="eqb_neq" class="idref" href="#eqb_neq"><span class="id" title="lemma">eqb_neq</span></a> : <span class="id" title="keyword">∀</span> <a id="x:190" class="idref" href="#x:190"><span class="id" title="binder">x</span></a> <a id="y:191" class="idref" href="#y:191"><span class="id" title="binder">y</span></a> : <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#nat"><span class="id" title="inductive">nat</span></a>,<br/>
&nbsp;&nbsp;<a class="idref" href="Logic.html#x:190"><span class="id" title="variable">x</span></a> <a class="idref" href="Basics.html#ad2ec4e405f68c46c0a176e3e94ae2e<sub>3</sub>"><span class="id" title="notation">=?</span></a> <a class="idref" href="Logic.html#y:191"><span class="id" title="variable">y</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Basics.html#false"><span class="id" title="constructor">false</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'&lt;-&gt;'_x"><span class="id" title="notation">↔</span></a> <a class="idref" href="Logic.html#x:190"><span class="id" title="variable">x</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'&lt;&gt;'_x"><span class="id" title="notation">≠</span></a> <a class="idref" href="Logic.html#y:191"><span class="id" title="variable">y</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="comment">(*&nbsp;FILL&nbsp;IN&nbsp;HERE&nbsp;*)</span> <span class="id" title="var">Admitted</span>.<br/>
<font size=-2>&#9744;</font>
</div>

<div class="doc"> 
<div class="paragraph"> </div>

<a id="lab203"></a><h4 class="section">Exercise: 3 stars, standard (eqb_list)</h4>
 Given a boolean operator <span class="inlinecode"><span class="id" title="var">eqb</span></span> for testing equality of elements of
    some type <span class="inlinecode"><span class="id" title="var">A</span></span>, we can define a function <span class="inlinecode"><span class="id" title="var">eqb_list</span></span> for testing
    equality of lists with elements in <span class="inlinecode"><span class="id" title="var">A</span></span>.  Complete the definition
    of the <span class="inlinecode"><span class="id" title="var">eqb_list</span></span> function below.  To make sure that your
    definition is correct, prove the lemma <span class="inlinecode"><span class="id" title="var">eqb_list_true_iff</span></span>. 
</div>
<div class="code">

<span class="id" title="keyword">Fixpoint</span> <a id="eqb_list" class="idref" href="#eqb_list"><span class="id" title="definition">eqb_list</span></a> {<a id="A:192" class="idref" href="#A:192"><span class="id" title="binder">A</span></a> : <span class="id" title="keyword">Type</span>} (<a id="eqb:193" class="idref" href="#eqb:193"><span class="id" title="binder">eqb</span></a> : <a class="idref" href="Logic.html#A:192"><span class="id" title="variable">A</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="Logic.html#A:192"><span class="id" title="variable">A</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="Basics.html#bool"><span class="id" title="inductive">bool</span></a>)<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(<a id="l<sub>1</sub>:194" class="idref" href="#l<sub>1</sub>:194"><span class="id" title="binder">l<sub>1</sub></span></a> <a id="l<sub>2</sub>:195" class="idref" href="#l<sub>2</sub>:195"><span class="id" title="binder">l<sub>2</sub></span></a> : <a class="idref" href="Poly.html#list"><span class="id" title="inductive">list</span></a> <a class="idref" href="Logic.html#A:192"><span class="id" title="variable">A</span></a>) : <a class="idref" href="Basics.html#bool"><span class="id" title="inductive">bool</span></a><br/>
&nbsp;&nbsp;<span class="comment">(*&nbsp;REPLACE&nbsp;THIS&nbsp;LINE&nbsp;WITH&nbsp;":=&nbsp;_your_definition_&nbsp;."&nbsp;*)</span>. <span class="id" title="var">Admitted</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Theorem</span> <a id="eqb_list_true_iff" class="idref" href="#eqb_list_true_iff"><span class="id" title="lemma">eqb_list_true_iff</span></a> :<br/>
&nbsp;&nbsp;<span class="id" title="keyword">∀</span> <a id="A:197" class="idref" href="#A:197"><span class="id" title="binder">A</span></a> (<a id="eqb:198" class="idref" href="#eqb:198"><span class="id" title="binder">eqb</span></a> : <a class="idref" href="Logic.html#A:197"><span class="id" title="variable">A</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="Logic.html#A:197"><span class="id" title="variable">A</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="Basics.html#bool"><span class="id" title="inductive">bool</span></a>),<br/>
&nbsp;&nbsp;&nbsp;&nbsp;<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">(</span></a><span class="id" title="keyword">∀</span> <a id="a<sub>1</sub>:199" class="idref" href="#a<sub>1</sub>:199"><span class="id" title="binder">a<sub>1</sub></span></a> <a id="a<sub>2</sub>:200" class="idref" href="#a<sub>2</sub>:200"><span class="id" title="binder">a<sub>2</sub></span></a>, <a class="idref" href="Logic.html#eqb:198"><span class="id" title="variable">eqb</span></a> <a class="idref" href="Logic.html#a<sub>1</sub>:199"><span class="id" title="variable">a<sub>1</sub></span></a> <a class="idref" href="Logic.html#a<sub>2</sub>:200"><span class="id" title="variable">a<sub>2</sub></span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Basics.html#true"><span class="id" title="constructor">true</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'&lt;-&gt;'_x"><span class="id" title="notation">↔</span></a> <a class="idref" href="Logic.html#a<sub>1</sub>:199"><span class="id" title="variable">a<sub>1</sub></span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Logic.html#a<sub>2</sub>:200"><span class="id" title="variable">a<sub>2</sub></span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">)</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a><br/>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="id" title="keyword">∀</span> <a id="l<sub>1</sub>:201" class="idref" href="#l<sub>1</sub>:201"><span class="id" title="binder">l<sub>1</sub></span></a> <a id="l<sub>2</sub>:202" class="idref" href="#l<sub>2</sub>:202"><span class="id" title="binder">l<sub>2</sub></span></a>, <a class="idref" href="Logic.html#eqb_list"><span class="id" title="axiom">eqb_list</span></a> <a class="idref" href="Logic.html#eqb:198"><span class="id" title="variable">eqb</span></a> <a class="idref" href="Logic.html#l<sub>1</sub>:201"><span class="id" title="variable">l<sub>1</sub></span></a> <a class="idref" href="Logic.html#l<sub>2</sub>:202"><span class="id" title="variable">l<sub>2</sub></span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Basics.html#true"><span class="id" title="constructor">true</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'&lt;-&gt;'_x"><span class="id" title="notation">↔</span></a> <a class="idref" href="Logic.html#l<sub>1</sub>:201"><span class="id" title="variable">l<sub>1</sub></span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Logic.html#l<sub>2</sub>:202"><span class="id" title="variable">l<sub>2</sub></span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
<span class="comment">(*&nbsp;FILL&nbsp;IN&nbsp;HERE&nbsp;*)</span> <span class="id" title="var">Admitted</span>.<br/>
<font size=-2>&#9744;</font>
</div>

<div class="doc"> 
<div class="paragraph"> </div>

<a id="lab204"></a><h4 class="section">Exercise: 2 stars, standard, especially useful (All_forallb)</h4>
 Recall the function <span class="inlinecode"><span class="id" title="var">forallb</span></span>, from the exercise
    <span class="inlinecode"><span class="id" title="var">forall_exists_challenge</span></span> in chapter <a href="Tactics.html"><span class="inlineref">Tactics</span></a>: 
</div>
<div class="code">

<span class="id" title="keyword">Fixpoint</span> <a id="forallb" class="idref" href="#forallb"><span class="id" title="definition">forallb</span></a> {<a id="X:203" class="idref" href="#X:203"><span class="id" title="binder">X</span></a> : <span class="id" title="keyword">Type</span>} (<a id="test:204" class="idref" href="#test:204"><span class="id" title="binder">test</span></a> : <a class="idref" href="Logic.html#X:203"><span class="id" title="variable">X</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="Basics.html#bool"><span class="id" title="inductive">bool</span></a>) (<a id="l:205" class="idref" href="#l:205"><span class="id" title="binder">l</span></a> : <a class="idref" href="Poly.html#list"><span class="id" title="inductive">list</span></a> <a class="idref" href="Logic.html#X:203"><span class="id" title="variable">X</span></a>) : <a class="idref" href="Basics.html#bool"><span class="id" title="inductive">bool</span></a> :=<br/>
&nbsp;&nbsp;<span class="id" title="keyword">match</span> <a class="idref" href="Logic.html#l:205"><span class="id" title="variable">l</span></a> <span class="id" title="keyword">with</span><br/>
&nbsp;&nbsp;| <a class="idref" href="Poly.html#2c60282cbb04e070c60ae01e76f3865a"><span class="id" title="notation">[]</span></a> ⇒ <a class="idref" href="Basics.html#true"><span class="id" title="constructor">true</span></a><br/>
&nbsp;&nbsp;| <span class="id" title="var">x</span> <a class="idref" href="Poly.html#:::x_'::'_x"><span class="id" title="notation">::</span></a> <span class="id" title="var">l'</span> ⇒ <a class="idref" href="Basics.html#andb"><span class="id" title="definition">andb</span></a> (<a class="idref" href="Logic.html#test:204"><span class="id" title="variable">test</span></a> <span class="id" title="var">x</span>) (<a class="idref" href="Logic.html#forallb:206"><span class="id" title="definition">forallb</span></a> <a class="idref" href="Logic.html#test:204"><span class="id" title="variable">test</span></a> <span class="id" title="var">l'</span>)<br/>
&nbsp;&nbsp;<span class="id" title="keyword">end</span>.<br/>
</div>

<div class="doc">
Prove the theorem below, which relates <span class="inlinecode"><span class="id" title="var">forallb</span></span> to the <span class="inlinecode"><span class="id" title="keyword">All</span></span>
    property defined above. 
</div>
<div class="code">

<span class="id" title="keyword">Theorem</span> <a id="forallb_true_iff" class="idref" href="#forallb_true_iff"><span class="id" title="lemma">forallb_true_iff</span></a> : <span class="id" title="keyword">∀</span> <a id="X:208" class="idref" href="#X:208"><span class="id" title="binder">X</span></a> <a id="test:209" class="idref" href="#test:209"><span class="id" title="binder">test</span></a> (<a id="l:210" class="idref" href="#l:210"><span class="id" title="binder">l</span></a> : <a class="idref" href="Poly.html#list"><span class="id" title="inductive">list</span></a> <a class="idref" href="Logic.html#X:208"><span class="id" title="variable">X</span></a>),<br/>
&nbsp;&nbsp;<a class="idref" href="Logic.html#forallb"><span class="id" title="definition">forallb</span></a> <a class="idref" href="Logic.html#test:209"><span class="id" title="variable">test</span></a> <a class="idref" href="Logic.html#l:210"><span class="id" title="variable">l</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Basics.html#true"><span class="id" title="constructor">true</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'&lt;-&gt;'_x"><span class="id" title="notation">↔</span></a> <a class="idref" href="Logic.html#All"><span class="id" title="axiom">All</span></a> (<span class="id" title="keyword">fun</span> <a id="x:211" class="idref" href="#x:211"><span class="id" title="binder">x</span></a> ⇒ <a class="idref" href="Logic.html#test:209"><span class="id" title="variable">test</span></a> <a class="idref" href="Logic.html#x:211"><span class="id" title="variable">x</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Basics.html#true"><span class="id" title="constructor">true</span></a>) <a class="idref" href="Logic.html#l:210"><span class="id" title="variable">l</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="comment">(*&nbsp;FILL&nbsp;IN&nbsp;HERE&nbsp;*)</span> <span class="id" title="var">Admitted</span>.<br/>
</div>

<div class="doc">
(Ungraded thought question) Are there any important properties of
    the function <span class="inlinecode"><span class="id" title="var">forallb</span></span> which are not captured by this
    specification? 
</div>
<div class="code">

<span class="comment">(*&nbsp;FILL&nbsp;IN&nbsp;HERE&nbsp;*)</span><br/>
<font size=-2>&#9744;</font>
</div>

<div class="doc"> 
<div class="paragraph"> </div>

<a id="lab205"></a><h2 class="section">Classical vs. Constructive Logic</h2>

<div class="paragraph"> </div>

 We have seen that it is not possible to test whether or not a
    proposition <span class="inlinecode"><span class="id" title="var">P</span></span> holds while defining a Coq function.  You may be
    surprised to learn that a similar restriction applies to <i>proofs</i>!
    In other words, the following intuitive reasoning principle is not
    derivable in Coq: 
</div>
<div class="code">

<span class="id" title="keyword">Definition</span> <a id="excluded_middle" class="idref" href="#excluded_middle"><span class="id" title="definition">excluded_middle</span></a> := <span class="id" title="keyword">∀</span> <a id="P:212" class="idref" href="#P:212"><span class="id" title="binder">P</span></a> : <span class="id" title="keyword">Prop</span>,<br/>
&nbsp;&nbsp;<a class="idref" href="Logic.html#P:212"><span class="id" title="variable">P</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#f031fe1957c4a4a8e217aa46af2b4e<sub>25</sub>"><span class="id" title="notation">∨</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#63a68285c81db8f9bc456233bb9ed181"><span class="id" title="notation">¬</span></a> <a class="idref" href="Logic.html#P:212"><span class="id" title="variable">P</span></a>.<br/>
</div>

<div class="doc">
To understand operationally why this is the case, recall
    that, to prove a statement of the form <span class="inlinecode"><span class="id" title="var">P</span></span> <span class="inlinecode">∨</span> <span class="inlinecode"><span class="id" title="var">Q</span></span>, we use the <span class="inlinecode"><span class="id" title="tactic">left</span></span>
    and <span class="inlinecode"><span class="id" title="tactic">right</span></span> tactics, which effectively require knowing which side
    of the disjunction holds.  But the universally quantified <span class="inlinecode"><span class="id" title="var">P</span></span> in
    <span class="inlinecode"><span class="id" title="var">excluded_middle</span></span> is an <i>arbitrary</i> proposition, which we know
    nothing about.  We don't have enough information to choose which
    of <span class="inlinecode"><span class="id" title="tactic">left</span></span> or <span class="inlinecode"><span class="id" title="tactic">right</span></span> to apply, just as Coq doesn't have enough
    information to mechanically decide whether <span class="inlinecode"><span class="id" title="var">P</span></span> holds or not inside
    a function. 
<div class="paragraph"> </div>

 However, if we happen to know that <span class="inlinecode"><span class="id" title="var">P</span></span> is reflected in some
    boolean term <span class="inlinecode"><span class="id" title="var">b</span></span>, then knowing whether it holds or not is trivial:
    we just have to check the value of <span class="inlinecode"><span class="id" title="var">b</span></span>. 
</div>
<div class="code">

<span class="id" title="keyword">Theorem</span> <a id="restricted_excluded_middle" class="idref" href="#restricted_excluded_middle"><span class="id" title="lemma">restricted_excluded_middle</span></a> : <span class="id" title="keyword">∀</span> <a id="P:213" class="idref" href="#P:213"><span class="id" title="binder">P</span></a> <a id="b:214" class="idref" href="#b:214"><span class="id" title="binder">b</span></a>,<br/>
&nbsp;&nbsp;<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">(</span></a><a class="idref" href="Logic.html#P:213"><span class="id" title="variable">P</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'&lt;-&gt;'_x"><span class="id" title="notation">↔</span></a> <a class="idref" href="Logic.html#b:214"><span class="id" title="variable">b</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Basics.html#true"><span class="id" title="constructor">true</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">)</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="Logic.html#P:213"><span class="id" title="variable">P</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#f031fe1957c4a4a8e217aa46af2b4e<sub>25</sub>"><span class="id" title="notation">∨</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#63a68285c81db8f9bc456233bb9ed181"><span class="id" title="notation">¬</span></a> <a class="idref" href="Logic.html#P:213"><span class="id" title="variable">P</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">intros</span> <span class="id" title="var">P</span> [] <span class="id" title="var">H</span>.<br/>
&nbsp;&nbsp;- <span class="id" title="tactic">left</span>. <span class="id" title="tactic">rewrite</span> <span class="id" title="var">H</span>. <span class="id" title="tactic">reflexivity</span>.<br/>
&nbsp;&nbsp;- <span class="id" title="tactic">right</span>. <span class="id" title="tactic">rewrite</span> <span class="id" title="var">H</span>. <span class="id" title="tactic">intros</span> <span class="id" title="var">contra</span>. <span class="id" title="tactic">discriminate</span> <span class="id" title="var">contra</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>

<div class="doc">
In particular, the excluded middle is valid for equations <span class="inlinecode"><span class="id" title="var">n</span></span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" title="var">m</span></span>,
    between natural numbers <span class="inlinecode"><span class="id" title="var">n</span></span> and <span class="inlinecode"><span class="id" title="var">m</span></span>. 
</div>
<div class="code">

<span class="id" title="keyword">Theorem</span> <a id="restricted_excluded_middle_eq" class="idref" href="#restricted_excluded_middle_eq"><span class="id" title="lemma">restricted_excluded_middle_eq</span></a> : <span class="id" title="keyword">∀</span> (<a id="n:215" class="idref" href="#n:215"><span class="id" title="binder">n</span></a> <a id="m:216" class="idref" href="#m:216"><span class="id" title="binder">m</span></a> : <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#nat"><span class="id" title="inductive">nat</span></a>),<br/>
&nbsp;&nbsp;<a class="idref" href="Logic.html#n:215"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Logic.html#m:216"><span class="id" title="variable">m</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#f031fe1957c4a4a8e217aa46af2b4e<sub>25</sub>"><span class="id" title="notation">∨</span></a> <a class="idref" href="Logic.html#n:215"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'&lt;&gt;'_x"><span class="id" title="notation">≠</span></a> <a class="idref" href="Logic.html#m:216"><span class="id" title="variable">m</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">intros</span> <span class="id" title="var">n</span> <span class="id" title="var">m</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">apply</span> (<a class="idref" href="Logic.html#restricted_excluded_middle"><span class="id" title="lemma">restricted_excluded_middle</span></a> (<span class="id" title="var">n</span> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <span class="id" title="var">m</span>) (<span class="id" title="var">n</span> <a class="idref" href="Basics.html#ad2ec4e405f68c46c0a176e3e94ae2e<sub>3</sub>"><span class="id" title="notation">=?</span></a> <span class="id" title="var">m</span>)).<br/>
&nbsp;&nbsp;<span class="id" title="tactic">symmetry</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">apply</span> <a class="idref" href="Logic.html#eqb_eq"><span class="id" title="lemma">eqb_eq</span></a>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>

<div class="doc">
It may seem strange that the general excluded middle is not
    available by default in Coq, since it is a standard feature of
    familiar logics like ZFC.  But there is a distinct advantage in
    not assuming the excluded middle: statements in Coq make stronger
    claims than the analogous statements in standard mathematics.
    Notably, when there is a Coq proof of <span class="inlinecode"><span class="id" title="tactic">∃</span></span> <span class="inlinecode"><span class="id" title="var">x</span>,</span> <span class="inlinecode"><span class="id" title="var">P</span></span> <span class="inlinecode"><span class="id" title="var">x</span></span>, it is
    always possible to explicitly exhibit a value of <span class="inlinecode"><span class="id" title="var">x</span></span> for which we
    can prove <span class="inlinecode"><span class="id" title="var">P</span></span> <span class="inlinecode"><span class="id" title="var">x</span></span> -- in other words, every proof of existence is
    <i>constructive</i>. 
<div class="paragraph"> </div>

 Logics like Coq's, which do not assume the excluded middle, are
    referred to as <i>constructive logics</i>.

<div class="paragraph"> </div>

    More conventional logical systems such as ZFC, in which the
    excluded middle does hold for arbitrary propositions, are referred
    to as <i>classical</i>. 
<div class="paragraph"> </div>

 The following example illustrates why assuming the excluded middle
    may lead to non-constructive proofs:

<div class="paragraph"> </div>

    <i>Claim</i>: There exist irrational numbers <span class="inlinecode"><span class="id" title="var">a</span></span> and <span class="inlinecode"><span class="id" title="var">b</span></span> such that
    <span class="inlinecode"><span class="id" title="var">a</span></span> <span class="inlinecode">^</span> <span class="inlinecode"><span class="id" title="var">b</span></span> (<span class="inlinecode"><span class="id" title="var">a</span></span> to the power <span class="inlinecode"><span class="id" title="var">b</span></span>) is rational.

<div class="paragraph"> </div>

    <i>Proof</i>: It is not difficult to show that <span class="inlinecode"><span class="id" title="var">sqrt</span></span> <span class="inlinecode">2</span> is irrational.
    If <span class="inlinecode"><span class="id" title="var">sqrt</span></span> <span class="inlinecode">2</span> <span class="inlinecode">^</span> <span class="inlinecode"><span class="id" title="var">sqrt</span></span> <span class="inlinecode">2</span> is rational, it suffices to take <span class="inlinecode"><span class="id" title="var">a</span></span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" title="var">b</span></span> <span class="inlinecode">=</span>
    <span class="inlinecode"><span class="id" title="var">sqrt</span></span> <span class="inlinecode">2</span> and we are done.  Otherwise, <span class="inlinecode"><span class="id" title="var">sqrt</span></span> <span class="inlinecode">2</span> <span class="inlinecode">^</span> <span class="inlinecode"><span class="id" title="var">sqrt</span></span> <span class="inlinecode">2</span> is
    irrational.  In this case, we can take <span class="inlinecode"><span class="id" title="var">a</span></span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" title="var">sqrt</span></span> <span class="inlinecode">2</span> <span class="inlinecode">^</span> <span class="inlinecode"><span class="id" title="var">sqrt</span></span> <span class="inlinecode">2</span> and
    <span class="inlinecode"><span class="id" title="var">b</span></span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" title="var">sqrt</span></span> <span class="inlinecode">2</span>, since <span class="inlinecode"><span class="id" title="var">a</span></span> <span class="inlinecode">^</span> <span class="inlinecode"><span class="id" title="var">b</span></span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" title="var">sqrt</span></span> <span class="inlinecode">2</span> <span class="inlinecode">^</span> <span class="inlinecode">(<span class="id" title="var">sqrt</span></span> <span class="inlinecode">2</span> <span class="inlinecode">×</span> <span class="inlinecode"><span class="id" title="var">sqrt</span></span> <span class="inlinecode">2)</span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" title="var">sqrt</span></span> <span class="inlinecode">2</span> <span class="inlinecode">^</span>
    <span class="inlinecode">2</span> <span class="inlinecode">=</span> <span class="inlinecode">2</span>.  <font size=-2>&#9744;</font>

<div class="paragraph"> </div>

    Do you see what happened here?  We used the excluded middle to
    consider separately the cases where <span class="inlinecode"><span class="id" title="var">sqrt</span></span> <span class="inlinecode">2</span> <span class="inlinecode">^</span> <span class="inlinecode"><span class="id" title="var">sqrt</span></span> <span class="inlinecode">2</span> is rational
    and where it is not, without knowing which one actually holds!
    Because of that, we finish the proof knowing that such <span class="inlinecode"><span class="id" title="var">a</span></span> and <span class="inlinecode"><span class="id" title="var">b</span></span>
    exist but we cannot determine what their actual values are (at least,
    not from this line of argument).

<div class="paragraph"> </div>

    As useful as constructive logic is, it does have its limitations:
    There are many statements that can easily be proven in classical
    logic but that have only much more complicated constructive proofs, and
    there are some that are known to have no constructive proof at
    all!  Fortunately, like functional extensionality, the excluded
    middle is known to be compatible with Coq's logic, allowing us to
    add it safely as an axiom.  However, we will not need to do so
    here: the results that we cover can be developed entirely
    within constructive logic at negligible extra cost.

<div class="paragraph"> </div>

    It takes some practice to understand which proof techniques must
    be avoided in constructive reasoning, but arguments by
    contradiction, in particular, are infamous for leading to
    non-constructive proofs.  Here's a typical example: suppose that
    we want to show that there exists <span class="inlinecode"><span class="id" title="var">x</span></span> with some property <span class="inlinecode"><span class="id" title="var">P</span></span>,
    i.e., such that <span class="inlinecode"><span class="id" title="var">P</span></span> <span class="inlinecode"><span class="id" title="var">x</span></span>.  We start by assuming that our conclusion
    is false; that is, <span class="inlinecode">¬</span> <span class="inlinecode"><span class="id" title="tactic">∃</span></span> <span class="inlinecode"><span class="id" title="var">x</span>,</span> <span class="inlinecode"><span class="id" title="var">P</span></span> <span class="inlinecode"><span class="id" title="var">x</span></span>. From this premise, it is not
    hard to derive <span class="inlinecode"><span class="id" title="keyword">∀</span></span> <span class="inlinecode"><span class="id" title="var">x</span>,</span> <span class="inlinecode">¬</span> <span class="inlinecode"><span class="id" title="var">P</span></span> <span class="inlinecode"><span class="id" title="var">x</span></span>.  If we manage to show that this
    intermediate fact results in a contradiction, we arrive at an
    existence proof without ever exhibiting a value of <span class="inlinecode"><span class="id" title="var">x</span></span> for which
    <span class="inlinecode"><span class="id" title="var">P</span></span> <span class="inlinecode"><span class="id" title="var">x</span></span> holds!

<div class="paragraph"> </div>

    The technical flaw here, from a constructive standpoint, is that
    we claimed to prove <span class="inlinecode"><span class="id" title="tactic">∃</span></span> <span class="inlinecode"><span class="id" title="var">x</span>,</span> <span class="inlinecode"><span class="id" title="var">P</span></span> <span class="inlinecode"><span class="id" title="var">x</span></span> using a proof of
    <span class="inlinecode">¬</span> <span class="inlinecode">¬</span> <span class="inlinecode">(<span class="id" title="tactic">∃</span></span> <span class="inlinecode"><span class="id" title="var">x</span>,</span> <span class="inlinecode"><span class="id" title="var">P</span></span> <span class="inlinecode"><span class="id" title="var">x</span>)</span>.  Allowing ourselves to remove double
    negations from arbitrary statements is equivalent to assuming the
    excluded middle, as shown in one of the exercises below.  Thus,
    this line of reasoning cannot be encoded in Coq without assuming
    additional axioms. 
<div class="paragraph"> </div>

<a id="lab206"></a><h4 class="section">Exercise: 3 stars, standard (excluded_middle_irrefutable)</h4>
 Proving the consistency of Coq with the general excluded middle
    axiom requires complicated reasoning that cannot be carried out
    within Coq itself.  However, the following theorem implies that it
    is always safe to assume a decidability axiom (i.e., an instance
    of excluded middle) for any <i>particular</i> Prop <span class="inlinecode"><span class="id" title="var">P</span></span>.  Why?  Because
    we cannot prove the negation of such an axiom.  If we could, we
    would have both <span class="inlinecode">¬</span> <span class="inlinecode">(<span class="id" title="var">P</span></span> <span class="inlinecode">∨</span> <span class="inlinecode">¬<span class="id" title="var">P</span>)</span> and <span class="inlinecode">¬</span> <span class="inlinecode">¬</span> <span class="inlinecode">(<span class="id" title="var">P</span></span> <span class="inlinecode">∨</span> <span class="inlinecode">¬<span class="id" title="var">P</span>)</span> (since <span class="inlinecode"><span class="id" title="var">P</span></span>
    implies <span class="inlinecode">¬</span> <span class="inlinecode">¬</span> <span class="inlinecode"><span class="id" title="var">P</span></span>, by lemma <span class="inlinecode"><span class="id" title="var">double_neg</span></span>, which we proved above),
    which would be a  contradiction.  But since we can't, it is safe
    to add <span class="inlinecode"><span class="id" title="var">P</span></span> <span class="inlinecode">∨</span> <span class="inlinecode">¬<span class="id" title="var">P</span></span> as an axiom.

<div class="paragraph"> </div>

    Succinctly: for any proposition P,
       <span class="inlinecode"><span class="id" title="var">Coq</span></span> <span class="inlinecode"><span class="id" title="keyword">is</span></span> <span class="inlinecode"><span class="id" title="var">consistent</span></span> <span class="inlinecode">==&gt;</span> <span class="inlinecode">(<span class="id" title="var">Coq</span></span> <span class="inlinecode">+</span> <span class="inlinecode"><span class="id" title="var">P</span></span> <span class="inlinecode">∨</span> <span class="inlinecode">¬<span class="id" title="var">P</span>)</span> <span class="inlinecode"><span class="id" title="keyword">is</span></span> <span class="inlinecode"><span class="id" title="var">consistent</span></span>.

<div class="paragraph"> </div>

    (Hint: You may need to come up with a clever assertion as the
    next step in the proof.) 
</div>
<div class="code">

<span class="id" title="keyword">Theorem</span> <a id="excluded_middle_irrefutable" class="idref" href="#excluded_middle_irrefutable"><span class="id" title="lemma">excluded_middle_irrefutable</span></a>: <span class="id" title="keyword">∀</span> (<a id="P:217" class="idref" href="#P:217"><span class="id" title="binder">P</span></a>:<span class="id" title="keyword">Prop</span>),<br/>
&nbsp;&nbsp;<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#63a68285c81db8f9bc456233bb9ed181"><span class="id" title="notation">¬</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#63a68285c81db8f9bc456233bb9ed181"><span class="id" title="notation">¬</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#63a68285c81db8f9bc456233bb9ed181"><span class="id" title="notation">(</span></a><a class="idref" href="Logic.html#P:217"><span class="id" title="variable">P</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#f031fe1957c4a4a8e217aa46af2b4e<sub>25</sub>"><span class="id" title="notation">∨</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#63a68285c81db8f9bc456233bb9ed181"><span class="id" title="notation">¬</span></a> <a class="idref" href="Logic.html#P:217"><span class="id" title="variable">P</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#63a68285c81db8f9bc456233bb9ed181"><span class="id" title="notation">)</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="id" title="tactic">unfold</span> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#not"><span class="id" title="definition">not</span></a>. <span class="id" title="tactic">intros</span> <span class="id" title="var">P</span> <span class="id" title="var">H</span>.<br/>
&nbsp;&nbsp;<span class="comment">(*&nbsp;FILL&nbsp;IN&nbsp;HERE&nbsp;*)</span> <span class="id" title="var">Admitted</span>.<br/>
<font size=-2>&#9744;</font>
</div>

<div class="doc"> 
<div class="paragraph"> </div>

<a id="lab207"></a><h4 class="section">Exercise: 3 stars, advanced (not_exists_dist)</h4>
 It is a theorem of classical logic that the following two
    assertions are equivalent:
<br/>
<span class="inlinecode">&nbsp;&nbsp;&nbsp;&nbsp;¬(<span class="id" title="tactic">∃</span> <span class="id" title="var">x</span>, ¬<span class="id" title="var">P</span> <span class="id" title="var">x</span>)<br/>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="id" title="keyword">∀</span> <span class="id" title="var">x</span>, <span class="id" title="var">P</span> <span class="id" title="var">x</span>
</span>    The <span class="inlinecode"><span class="id" title="var">dist_not_exists</span></span> theorem above proves one side of this
    equivalence. Interestingly, the other direction cannot be proved
    in constructive logic. Your job is to show that it is implied by
    the excluded middle. 
</div>
<div class="code">

<span class="id" title="keyword">Theorem</span> <a id="not_exists_dist" class="idref" href="#not_exists_dist"><span class="id" title="lemma">not_exists_dist</span></a> :<br/>
&nbsp;&nbsp;<a class="idref" href="Logic.html#excluded_middle"><span class="id" title="definition">excluded_middle</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a><br/>
&nbsp;&nbsp;<span class="id" title="keyword">∀</span> (<a id="X:218" class="idref" href="#X:218"><span class="id" title="binder">X</span></a>:<span class="id" title="keyword">Type</span>) (<a id="P:219" class="idref" href="#P:219"><span class="id" title="binder">P</span></a> : <a class="idref" href="Logic.html#X:218"><span class="id" title="variable">X</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <span class="id" title="keyword">Prop</span>),<br/>
&nbsp;&nbsp;&nbsp;&nbsp;<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#63a68285c81db8f9bc456233bb9ed181"><span class="id" title="notation">¬</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#63a68285c81db8f9bc456233bb9ed181"><span class="id" title="notation">(</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#a883bdd010993579f99d60b3775bcf54"><span class="id" title="notation">∃</span></a> <a id="x:220" class="idref" href="#x:220"><span class="id" title="binder">x</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#a883bdd010993579f99d60b3775bcf54"><span class="id" title="notation">,</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#63a68285c81db8f9bc456233bb9ed181"><span class="id" title="notation">¬</span></a> <a class="idref" href="Logic.html#P:219"><span class="id" title="variable">P</span></a> <a class="idref" href="Logic.html#x:220"><span class="id" title="variable">x</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#63a68285c81db8f9bc456233bb9ed181"><span class="id" title="notation">)</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">(</span></a><span class="id" title="keyword">∀</span> <a id="x:221" class="idref" href="#x:221"><span class="id" title="binder">x</span></a>, <a class="idref" href="Logic.html#P:219"><span class="id" title="variable">P</span></a> <a class="idref" href="Logic.html#x:221"><span class="id" title="variable">x</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">)</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
&nbsp;&nbsp;<span class="comment">(*&nbsp;FILL&nbsp;IN&nbsp;HERE&nbsp;*)</span> <span class="id" title="var">Admitted</span>.<br/>
<font size=-2>&#9744;</font>
</div>

<div class="doc"> 
<div class="paragraph"> </div>

<a id="lab208"></a><h4 class="section">Exercise: 5 stars, standard, optional (classical_axioms)</h4>
 For those who like a challenge, here is an exercise taken from the
    Coq'Art book by Bertot and Casteran (p. 123).  Each of the
    following four statements, together with <span class="inlinecode"><span class="id" title="var">excluded_middle</span></span>, can be
    considered as characterizing classical logic.  We can't prove any
    of them in Coq, but we can consistently add any one of them as an
    axiom if we wish to work in classical logic.

<div class="paragraph"> </div>

    Prove that all five propositions (these four plus <span class="inlinecode"><span class="id" title="var">excluded_middle</span></span>)
    are equivalent.

<div class="paragraph"> </div>

    Hint: Rather than considering all pairs of statements pairwise,
    prove a single circular chain of implications that connects them
    all. 
</div>
<div class="code">

<span class="id" title="keyword">Definition</span> <a id="peirce" class="idref" href="#peirce"><span class="id" title="definition">peirce</span></a> := <span class="id" title="keyword">∀</span> <a id="P:222" class="idref" href="#P:222"><span class="id" title="binder">P</span></a> <a id="Q:223" class="idref" href="#Q:223"><span class="id" title="binder">Q</span></a>: <span class="id" title="keyword">Prop</span>,<br/>
&nbsp;&nbsp;<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">((</span></a><a class="idref" href="Logic.html#P:222"><span class="id" title="variable">P</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="Logic.html#Q:223"><span class="id" title="variable">Q</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">)</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="Logic.html#P:222"><span class="id" title="variable">P</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">)</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="Logic.html#P:222"><span class="id" title="variable">P</span></a>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Definition</span> <a id="double_negation_elimination" class="idref" href="#double_negation_elimination"><span class="id" title="definition">double_negation_elimination</span></a> := <span class="id" title="keyword">∀</span> <a id="P:224" class="idref" href="#P:224"><span class="id" title="binder">P</span></a>:<span class="id" title="keyword">Prop</span>,<br/>
&nbsp;&nbsp;<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#63a68285c81db8f9bc456233bb9ed181"><span class="id" title="notation">~~</span></a><a class="idref" href="Logic.html#P:224"><span class="id" title="variable">P</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="Logic.html#P:224"><span class="id" title="variable">P</span></a>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Definition</span> <a id="de_morgan_not_and_not" class="idref" href="#de_morgan_not_and_not"><span class="id" title="definition">de_morgan_not_and_not</span></a> := <span class="id" title="keyword">∀</span> <a id="P:225" class="idref" href="#P:225"><span class="id" title="binder">P</span></a> <a id="Q:226" class="idref" href="#Q:226"><span class="id" title="binder">Q</span></a>:<span class="id" title="keyword">Prop</span>,<br/>
&nbsp;&nbsp;<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#63a68285c81db8f9bc456233bb9ed181"><span class="id" title="notation">~(~</span></a><a class="idref" href="Logic.html#P:225"><span class="id" title="variable">P</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#ba2b0e492d2b4675a0acf3ea92aabadd"><span class="id" title="notation">∧</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#63a68285c81db8f9bc456233bb9ed181"><span class="id" title="notation">¬</span></a><a class="idref" href="Logic.html#Q:226"><span class="id" title="variable">Q</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#63a68285c81db8f9bc456233bb9ed181"><span class="id" title="notation">)</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="Logic.html#P:225"><span class="id" title="variable">P</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#f031fe1957c4a4a8e217aa46af2b4e<sub>25</sub>"><span class="id" title="notation">∨</span></a> <a class="idref" href="Logic.html#Q:226"><span class="id" title="variable">Q</span></a>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Definition</span> <a id="implies_to_or" class="idref" href="#implies_to_or"><span class="id" title="definition">implies_to_or</span></a> := <span class="id" title="keyword">∀</span> <a id="P:227" class="idref" href="#P:227"><span class="id" title="binder">P</span></a> <a id="Q:228" class="idref" href="#Q:228"><span class="id" title="binder">Q</span></a>:<span class="id" title="keyword">Prop</span>,<br/>
&nbsp;&nbsp;<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">(</span></a><a class="idref" href="Logic.html#P:227"><span class="id" title="variable">P</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="Logic.html#Q:228"><span class="id" title="variable">Q</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">)</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">(</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#63a68285c81db8f9bc456233bb9ed181"><span class="id" title="notation">¬</span></a><a class="idref" href="Logic.html#P:227"><span class="id" title="variable">P</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#f031fe1957c4a4a8e217aa46af2b4e<sub>25</sub>"><span class="id" title="notation">∨</span></a> <a class="idref" href="Logic.html#Q:228"><span class="id" title="variable">Q</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'-&gt;'_x"><span class="id" title="notation">)</span></a>.<br/><hr class='doublespaceincode'/>
<span class="comment">(*&nbsp;FILL&nbsp;IN&nbsp;HERE&nbsp;*)</span><br/>
<font size=-2>&#9744;</font>
</div>

<div class="code">

<span class="comment">(*&nbsp;2021-08-11&nbsp;15:08&nbsp;*)</span><br/>
</div>
</div>

<div id="footer">
<hr/><a href="coqindex.html">Index</a><hr/>This page has been generated by <a href="http://coq.inria.fr/">coqdoc</a>
</div>

</div>

</body>
</html>